下載安裝包:html
https://www.postgresql.org/ftp/source/v12.0/
編譯依賴安裝:
python
yum -y install lrzsz sysstat e4fsprogs ntp readline-devel zlib zlib-devel openssl\ openssl-devel pam-devel libxml2-devel libxslt-devel python-devel tcl-devel gcc make smartmontools flex bison perl perl-devel perl-ExtUtils* OpenIPMI-tools systemtap-sdt-devel
編譯sql
./configure --prefix=/usr/local/postgresql-12.0 --datadir=/usr/local/postgresql-12.0/datas\ --htmldir=/usr/local/postgresql-12.0/docs --with-perl --with-openssl --enable-dtrace\ --enable-debug
建立啓動用戶數據庫
groupadd postgres useradd -g postgres postgres
建立數據庫文件存儲目錄並受權此目錄給數據庫啓動用戶
bash
mkdir -p /usr/local/postgresql-12.0/data chown -R postgres:postgres /usr/local/postgresql-12.0
切換用戶並初始化數據庫
socket
su postgres ./initdb -D /usr/local/postgresql-12.0/data
配置IP訪問模式
ide
vi /usr/local/postgresql/data/pg_hba.conf # 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 all postgres 0.0.0.0/0 trust
配置監聽地址、鏈接端口post
vi /usr/local/postgresql/data/postgresql.conf #------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - #listen_addresses = 'localhost' # what IP address(es) to listen on; listen_addresses = '*' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all # (change requires restart) #port = 5432 # (change requires restart) max_connections = 100 # (change requires restart) #superuser_reserved_connections = 3 # (change requires restart) #unix_socket_directories = '/tmp' # comma-separated list of directories # (change requires restart)
啓動數據庫
flex
su postgres /usr/local/postgresql/bin/pg_ctl -D /usr/local/postgresql/data -l logfile start
登陸數據庫
ui
/usr/local/pgsql/bin/psql
更改數據庫密碼
postgres=# \password postgres
建立用戶
create user sonar with password 'sonar'
建立數據庫
create database sonar
數據庫受權給指定用戶
grant all on database sonar to sonar進入數據庫
\c + 數據庫名稱 postgres=# \c sonar You are now connected to database "sonar" as user "postgres".