安装PostgreSQL后的初始化操作

安装环境
[root@localhost ~]# hostnamectl
   Static hostname: (unset)
Transient hostname: localhost
         Icon name: computer-vm
           Chassis: vm 🖴
        Machine ID: 1d71fe6ef4c74a1684adcdaa8b7d4823
           Boot ID: bf812fd7a4374a74b891c8c55a6ebd1b
    Virtualization: vmware
  Operating System: CentOS Stream 9
       CPE OS Name: cpe:/o:centos:centos:9
            Kernel: Linux 5.14.0-527.el9.aarch64
      Architecture: arm64
   Hardware Vendor: VMware, Inc.
    Hardware Model: VMware20,1
  Firmware 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=# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS

postgres=#

这里列出的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,以免出现兼容问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值