环境: 银河麒麟v10(yum源更换为华为 centos 7.9)
pgsql 11.16
一、主库安装配置:
1.安装依赖包
[root @kylin ]$ yum -y install readline gcc -y readline-devel zlib-devel
2.编译安装
[root @kylin ]$ tar -xvf postgresql-11.6.tar.gz
[root @kylin ]$ mkdir -p /opt/postgresql-11.6
[root @kylin ]$ cd /opt/postgresql-11.6
[root @kylin ]$ ./configure --prefix=/opt/postgresql-11.6 --with-blocksize=32 && make && make install
3.创建相应的用户
[root @kylin ]$ groupadd postgres
[root @kylin ]$ useradd -g postgres postgres
创建数据及日志目录,并做相应授权
[root @kylin ]$ mkdir -p /opt/postgresql-11.6/{data,log}
[root @kylin ]$ chown -R postgres:postgres /opt/postgresql-11.6
4.初始化数据库
[root @kylin ]$ su - postgres
[postgres@kylin bin]$ cd /opt/postgresql-11.6/bin
[postgres@kylin bin]$ ./initdb -D /opt/postgresql-11.6/data/
[postgres@kylin bin]$ ./pg_ctl -D /opt/postgresql-11.6/data/ -l /opt/postgresql-11.6/log/postgres.log start
waiting for server to start.... done
server started
[postgres@kylin bin]$ cd ~
[postgres@kylin ~]$ ls
[postgres@kylin ~]$ pwd
/home/postgres
[postgres@kylin ~]$ vim .bash_profile
# Source /root/.bashrc if user has one
[ -f ~/.bashrc ] && . ~/.bashrc
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/opt/postgresql-11.6/bin
export PATH
~
".bash_profile" 6L, 149C written
[postgres@kylin ~]$ source ~/.bash_profile
[postgres@kylin ~]$ cd /opt/postgresql-11.6/
[postgres@kylin postgresql-11.6]$ ls
bin data include lib log share
[postgres@kylin postgresql-11.6]$ cd bin
[postgres@kylin bin]$ ./pg_ctl -D /opt/postgresql-11.6/data/ -l /opt/postgresql-11.6/log/postgres.log restart
waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
[postgres@kylin bin]$ ./psql -p 5555
psql (11.6)
Type "help" for help.
postgres=# ALTER USER postgres WITH PASSWORD 'postgres';
ALTER ROLE
postgres=# select * from pg_shadow ;
usename | usesysid | usecreatedb | usesuper | userepl | usebypass
rls | passwd | valuntil | useconfig
----------+----------+-------------+----------+---------+----------
----+-------------------------------------+----------+-----------
postgres | 10 | t | t | t | t
| md53175bce1d3201d16594cebf9d7eb3f9d | |
(1 row)
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Ac
cess privileges
-----------+----------+----------+-------------+-------------+-----
------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/p
ostgres +
| | | | | post
gres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/p
ostgres +
| | | | | post
gres=CTc/postgres
(3 rows)
postgres=# \q
[postgres@kylin bin]$ ./pg_ctl -D /opt/postgresql-11.6/data/ -l /opt/postgresql-11.6/log/postgres.log restart
waiting for server to shut down.... done
server stopped
waiting for server to start.... done
server started
[postgres@kylin bin]$ vim /opt/postgresql-11.6/data/postgresql.conf
# with the "SET" SQL command.
#
# Memory units: kB = kilobytes Time units: ms = milliseconds
# MB = megabytes s = seconds
# GB = gigabytes min = minutes
# TB = terabytes h = hours
# d = days
#------------------------------------------------------------------------------
# FILE LOCATIONS
#------------------------------------------------------------------------------
# The default values of these variables are driven from the -D command-line
# option or PGDATA environment variable, represented here as ConfigDir.
#data_directory = 'ConfigDir' # use data in another directory
# (change requires restart)
#hba_file = 'ConfigDir/pg_hba.conf' # host-based authentication file
# (change requires restart)
#ident_file = 'ConfigDir/pg_ident.conf' # ident configuration file
# (change requires restart)
# If external_pid_file is not explicitly set, no extra PID file is written.
#external_pid_file = '' # write an extra PID file
# (change requires restart)
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
#listen_addresses = 'localhost' # what IP address(es) to listen on;
listen_addresses = '*'
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
port=5555
wal_level = replica
archive_mode = on
archive_command = 'cp %p /opt/postgresql-11.6/data/pg_archive/%f'
##%p = path of file to archive
##%f = file name only
max_wal_senders = 6
wal_keep_segments = 10240
wal_sender_timeout = 60s
[postgres@kylin bin]$ vim ../data/pg_hba.conf
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the server receives a
# SIGHUP signal. If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# CAUTION: Configuring the system for local "trust" authentication
# allows any local user to connect as any PostgreSQL user, including
# the database superuser. If you do not trust all your local users,
# use another authentication method.
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host replication repl 192.168.1.6/24 md5
host all repl 192.168.1.6/24 trust
[postgres@kylin bin]$ ./pg_ctl -D /opt/postgresql-11.6/data reload
[postgres@kylin bin]$ ./pg_ctl -D /opt/postgresql-11.6/data/ -l /opt/postgresql-11.6/log/postgres.log restart
waiting for server to shut down.... done
server stopped
waiting for ser
参看: https://www.cnblogs.com/likecoke/p/15715095.html
https://www.postgresql.org/ftp/source/v10.20/