irpas技术客

亲测可用——PostgresSQL安装教程_唐山大兄dei_pgsql安装

网络 4038

PostgresSQL安装教程 一、下载安装二、启动运行三、设置密码和远程链接四、卸载postgresSql

一、下载安装

首先官网先选择对应的操作系统 https://www.postgresql.org/download/

然后选择对应的pg库版本,现在最新版为14,为了稳定起见我们选择了12

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

这个命令可能要等待一小会,会出现很多的Another app is currently holding the yum lock; waiting for it to exit… 一定不要退出!!!!切记

出现下面这样就是安装成功了。postgresSql默认端口是5432。

二、启动运行

现在是没有启动的状态,我们分别执行:

# Optionally initialize the database and enable automatic start: sudo /usr/pgsql-12/bin/postgresql-12-setup initdb sudo systemctl enable postgresql-12 sudo systemctl start postgresql-12

执行sudo /usr/pgsql-12/bin/postgresql-12-setup initdb可能会遇到这个问题: initdb: 错误: 无法访问目录 “/var/lib/pgsql/12/data”: 权限不够

cd /var/lib/ chown -R postgres:postgres pgsql

一定要按照上面的操作命令去执行,少一步都会报错。

三、设置密码和远程链接

设置密码:

sudo passwd postgres 查看postgres相关用户: su postgres postgres=# psql postgres-# \l

在CentOS上,默认的PostgreSQL数据目录是/var/lib/pgsql/版本号/data navicate远程的时候宝这个错误,链接不上,所以我们还要修改一下postgresql的配置文件: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host"localhost" (:1) and acceptingTCP/IP connections on port 5433 ?

设置允许其他IP访问:

修改该配置文件中的参数,必须重启 postgreSql服务,若要允许其它IP地址访问 该主机数据库,则必须修改 postgresql.conf 中的参数 listen_addresses 为 * 重启:systemctl restart postgresql-12.service 或者 pg_ctl reload 或者 执行SELECT pg_reload_conf()

但是我们为了安全性一般都不会上面的设置,上面的配置只是校验了用户名,并没有校验密码,不输入密码也能链接数据库。一般远程链接都需要密码才行。下面配置是每次远程连接时首先校验密码:

vim pg_hba.conf

然后重启,远程连接:

systemctl restart postgresql-12.service

如果遇到远程连接时报了如下错误: postgresql 口令: psql: 致命错误: 用户 认证失败 psql :致命错误:用户postgres Password 认证失败 不要慌,首先登录pg库,改成你像设置的密码就可以了:

sudo -u postgres psql ALTER USER postgres WITH PASSWORD 'postgres'; 四、卸载postgresSql

一、首先执行以下命令:

[root@localhost ~]# rpm -qa | grep postgresql postgresql12-libs-12.9-1PGDG.rhel7.x86_64 postgresql-server-9.2.24-4.el7_8.x86_64 postgresql12-server-12.9-1PGDG.rhel7.x86_64 postgresql-9.2.24-4.el7_8.x86_64 postgresql12-12.9-1PGDG.rhel7.x86_64 postgresql-libs-9.2.24-4.el7_8.x86_64 yum remove postgresql12-libs-12.9-1PGDG.rhel7.x86_64

二、删除服务管理脚本

rm -f /etc/init.d/postgresql-10


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #pgsql安装 #首先官网先选择对应的操作系统 #yum #install #y