centos6离线安装postgresql12

准备工作

下载安装包

点击去官网下载

百度网盘下载:

链接:https://pan.baidu.com/s/1KtR03zKCpjxDC1jW25V0bg 
提取码:x9wi 

上传服务器

在这里插入图片描述

开始安装

依次执行以下命令,顺便不能错,否则会导致安装失败
[root@localhost install]# rpm -ivh postgresql12-libs-12.3-1PGDG.rhel6.x86_64.rpm
[root@localhost install]# rpm -ivh postgresql12-12.3-1PGDG.rhel6.x86_64.rpm
[root@localhost install]# rpm -ivh postgresql12-server-12.3-1PGDG.rhel6.x86_64.rpm
[root@localhost install]# rpm -ivh postgresql12-contrib-12.3-1PGDG.rhel6.x86_64.rpm

在这里插入图片描述

初始化数据库,第一要在/usr/pgsql-12/bin/目录下
[root@localhost bin]# cd /usr/pgsql-12/bin/
[root@localhost bin]# service postgresql-12 initdb

以上不行的话,执行

[root@localhost bin]# /usr/pgsql-12/bin/postgresql-12-setup initdb
设置开机启动
[root@localhost bin]# chkconfig postgresql-12 on
启动postgresql12数据库
[root@localhost bin]# service postgresql-12 start

在这里插入图片描述

本地登录
[root@localhost bin]# su postgres
bash-4.1$ psql
psql (12.3)
Type "help" for help.
postgres=# 

在这里插入图片描述

修改配 postgresql.conf 、pg_hba.conf

[root@localhost ~]# cd /var/lib/pgsql/12/data
[root@localhost data]# ll
total 132
drwx------. 5 postgres postgres  4096 Jul 14 17:32 base
-rw-------. 1 postgres postgres    30 Jul 14 17:32 current_logfiles
drwx------. 2 postgres postgres  4096 Jul 14 17:32 global
drwx------. 2 postgres postgres  4096 Jul 14 17:32 log
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_commit_ts
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_dynshmem
-rw-------. 1 postgres postgres  4269 Jul 14 17:30 pg_hba.conf
-rw-------. 1 postgres postgres  1636 Jul 14 17:30 pg_ident.conf
drwx------. 4 postgres postgres  4096 Jul 14 17:37 pg_logical
drwx------. 4 postgres postgres  4096 Jul 14 17:30 pg_multixact
drwx------. 2 postgres postgres  4096 Jul 14 17:32 pg_notify
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_replslot
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_serial
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_snapshots
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_stat
drwx------. 2 postgres postgres  4096 Jul 14 17:46 pg_stat_tmp
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_subtrans
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_tblspc
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_twophase
-rw-------. 1 postgres postgres     3 Jul 14 17:30 PG_VERSION
drwx------. 3 postgres postgres  4096 Jul 14 17:30 pg_wal
drwx------. 2 postgres postgres  4096 Jul 14 17:30 pg_xact
-rw-------. 1 postgres postgres    88 Jul 14 17:30 postgresql.auto.conf
-rw-------. 1 postgres postgres 26612 Jul 14 17:30 postgresql.conf
-rw-------. 1 postgres postgres    57 Jul 14 17:32 postmaster.opts
-rw-------. 1 postgres postgres   104 Jul 14 17:32 postmaster.pid
pg_hba.conf修改如下

在这里插入图片描述

postgresql.conf修改如下

在这里插入图片描述

重启服务
[root@localhost data]# service postgresql-12 restart

服务器登录之后创建用户密码
[root@localhost bin]# su postgres
bash-4.1$ psql
psql (12.3)
Type "help" for help.

postgres=# create user root with password 'datahome123';
CREATE ROLE
postgres=# alter role root login;
ALTER ROLE
postgres=# alter role root superuser createrole createdb;
ALTER ROLE
postgres=# \dt
Did not find any relations.
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 root      | Superuser, Create role, Create DB                          | {}

在这里插入图片描述

使用navicat Premium 远程登录数据库

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 CentOS 7 上离线安装 PostgreSQL 12,请按照以下步骤进行操作: 1. 首先,从 PostgreSQL 官方网站下载 PostgreSQL 12 的离线安装包(tar.gz 格式)到您的本地机器上。您可以在以下链接中找到适合您操作系统的版本:https://www.postgresql.org/download/ 2. 在您的本地机器上创建一个目录用于安装 PostgreSQL。假设您创建了一个名为 "postgres_install" 的目录。 3. 将下载的 PostgreSQL 12 安装包复制到 "postgres_install" 目录中。 4. 打开命令行终端,并切换到 "postgres_install" 目录。 5. 解压缩安装包。在命令行中运行以下命令: ``` tar -xzvf postgresql-12.*.tar.gz ``` 请将 "postgresql-12.*.tar.gz" 替换为您下载的实际文件名。 6. 切换到解压缩后的目录。在命令行中运行以下命令: ``` cd postgresql-12.* ``` 7. 配置和编译 PostgreSQL。在命令行中运行以下命令: ``` ./configure --prefix=/usr/local/pgsql make ``` 这将配置和编译 PostgreSQL,并将其安装到 "/usr/local/pgsql" 目录下。 8. 安装 PostgreSQL。在命令行中以超级用户身份运行以下命令: ``` sudo make install ``` 这将安装 PostgreSQL 到系统中。 9. 创建数据目录并设置权限。在命令行中以超级用户身份运行以下命令: ``` sudo mkdir /usr/local/pgsql/data sudo chown postgres:postgres /usr/local/pgsql/data ``` 这将创建一个名为 "data" 的目录,并将其所有权分配给 "postgres" 用户和组。 10. 初始化数据库集群。在命令行中以 "postgres" 用户身份运行以下命令: ``` /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data ``` 11. 启动 PostgreSQL 服务器。在命令行中以 "postgres" 用户身份运行以下命令: ``` /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start ``` 现在,您已经成功离线安装PostgreSQL 12,并启动了 PostgreSQL 服务器。您可以使用 psql 命令行工具或其他客户端连接到您的 PostgreSQL 数据库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值