centos6离线安装postgresql12
准备工作
下载安装包
百度网盘下载:
链接: https://pan.baidu.com/s/1mK7adSDSEZMyKvDSwg-v3A
提取码: ipaf
上传服务器
开始安装
依次执行以下命令,顺便不能错,否则会导致安装失败
[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 | {}