PostgreSQL安装

发布时间 2024-01-08 13:16:16作者: 粒子先生

下载安装

yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum install -y postgresql12-server

初始化

/usr/pgsql-12/bin/postgresql-12-setup initdb

坑:
修改临时目录路径,并修改目录/tmp/pgsql的权限

vim /var/lib/pgsql/12/data/postgresql.conf
unix_socket_directories = '/var/run/postgresql, /tmp/pgsql'

chown postgres:postgres /tmp/pgsql

修改postgresql.conf

vim /var/lib/pgsql/12/data/postgresql.conf
listen_addresses = '*' # what IP address(es) to listen on;
unix_socket_directories = '/var/run/postgresql, /tmp/pgsql' # comma-separated list of directories

修改pg_hba.conf

vim /var/lib/pgsql/12/data/pg_hba.conf
#host all all 127.0.0.1/32 ident
host all all 0.0.0.0/0 md5

启动

systemctl enable postgresql-12
systemctl start postgresql-12

修改密码、授权

su - postgres
psql

ALTER USER postgres with encrypted password 'xxxxxxxxxxx';
GRANT ALL PRIVILEGES ON DATABASE postgres TO postgres
\q

连接验证