欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 新车 > 安装PostgreSQL后的初始化操作

安装PostgreSQL后的初始化操作

2025/5/14 13:17:15 来源:https://blog.csdn.net/weixin_39712991/article/details/144869051  浏览:    关键词:安装PostgreSQL后的初始化操作
安装环境
[root@localhost ~]# hostnamectlStatic hostname: (unset)
Transient hostname: localhostIcon name: computer-vmChassis: vm 🖴Machine ID: 1d71fe6ef4c74a1684adcdaa8b7d4823Boot ID: bf812fd7a4374a74b891c8c55a6ebd1bVirtualization: vmwareOperating System: CentOS Stream 9CPE OS Name: cpe:/o:centos:centos:9Kernel: Linux 5.14.0-527.el9.aarch64Architecture: arm64Hardware Vendor: VMware, Inc.Hardware Model: VMware20,1Firmware Version: VMW201.00V.24006586.BA64.2406042154
[root@localhost ~]#
前置准备

安装官网的安装步骤安装:https://www.postgresql.org/download/linux/redhat/

修改用户密码

在安装PostgreSQL时,会创建一个postgres的操作系统用户,可以切换到该用户做初始操作

[root@localhost ~]# sudo -i -u postgres
[postgres@localhost ~]$ psql
psql (17.2)
Type "help" for help.postgres=#

查看当前库下用户信息

postgres=# \duList of rolesRole name |                         Attributes
-----------+------------------------------------------------------------postgres  | Superuser, Create role, Create DB, Replication, Bypass RLSpostgres=#

这里列出的postgres也是默认的用户,可以看到这是个超级用户
为这个超级用户设置密码

postgres=# ALTER USER postgres WITH PASSWORD 'pgadmin123';
ALTER ROLE
postgres=#
设置远程连接

首先,找到库的配置文件

[postgres@localhost ~]$ psql -U postgres -c 'SHOW config_file'config_file
----------------------------------------/var/lib/pgsql/17/data/postgresql.conf
(1 row)[postgres@localhost ~]$

找到配置文件的listen_addresses,值修改为‘*’

# - Connection Settings -listen_addresses = '*'                  # what IP address(es) to listen on;
修改防火墙
[root@localhost ~]# sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
Warning: ALREADY_ENABLED: 5432:tcp
success
[root@localhost ~]#
[root@localhost ~]# sudo firewall-cmd --reload
success
[root@localhost ~]#
重启
[root@localhost ~]# systemctl restart postgresql-17
[root@localhost ~]#
连接

如果使用客户端连接,注意使用最新的JDBC jar,以免出现兼容问题

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词