暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL源码方式安装

实验环境

主机名 ip 操作系统 postgresql版本
pc001 192.168.202.129 centos-stream-9 postgresql-16.1.tar.gz

安装依赖包

[root@pc001 ~]# yum -y install bison flex readline-devel zlib zlib-devel openssl-devel libicu-devel make gcc

创建用户与用户组

# 创建postgres组,创建postgres用户,并将其加到postgres组下,修改postgres用户密码 [root@pc001 soft]# groupadd postgres [root@pc001 soft]# useradd -g postgres postgres [root@pc001 soft]# passwd postgres --密码为:123456 --上传安装文件到soft目录下 [root@pc001 /]# chown -R postgres:postgres /soft/ [root@pc001 /]# mkdir -p /usr/postgres/16.1 [root@pc001 /]# chown -R postgres:postgres /usr/postgres/16.1/data/

使用postres用户安装

[root@pc001 soft]# su - postgres [postgres@pc001 ~]$ cd /soft/ [postgres@pc001 soft]$ tar -zxvf postgresql-16.1.tar.gz --检查解压后的文件夹里的configure是否有执行权限,如果没有的话要先权限为可执行。 # make world 为编译所有包内的插件,make install-world安装包内的所有插件 [postgres@pc001 soft]$ cd postgresql-16.1/ [postgres@pc001 postgresql-16.1]$ ./configure --prefix=/usr/postgres/16.1 [postgres@pc001 postgresql-16.1]$ make world [postgres@pc001 postgresql-16.1]$ make install-world

配置环境变量

[postgres@pc001 bin]$ vim ~/.bashrc PGHOME="/usr/postgres/16.1" PATH=$PATH:$PGHOME/bin export PATH PGDATA="/usr/postgres/16.1/data" export PGDATA [postgres@pc001 bin]$ source ~/.bashrc

初始化数据库

[postgres@pc001 postgresql-16.1]$ /usr/postgres/16.1/bin/initdb -D /usr/postgres/16.1/data

防火墙开通端口

firewall-cmd --zone=public --add-port=5432/tcp --permanent firewall-cmd --reload

修改postgres数据库用户密码

postgres=# ALTER USER postgres PASSWORD 'postgres';

配置pg_hba.conf文件,修改后需要重新加载配置文件

# 修改以下行的 method 为md5,这样登录postgres用户时要使用密码 [postgres@pc001 soft]$ vim /usr/postgres/16.1/data/pg_hba.conf host all all 0.0.0.0/0 md5

远程访问配置

# 修改以下行的 listen_addresses 内容为 * 。 [postgres@pc001 soft]$ vim /usr/postgres/16.1/data/postgresql.conf listen_addresses = '*' --修改pg_hba.conf后需要重启数据库服务

数据库启动与关闭

# 前台方式启动 [postgres@pc001 soft]$ pg_ctl start # 后台方式启动 [postgres@pc001 soft]$ pg_ctl start >logfile 2>&1 & # 关闭 [postgres@pc001 soft]$ pg_ctl stop

数据库运行状态

  • 查看 postgresql 相关进程

    # 从以下输出可看到相关过程 checkpointer、background writer... [postgres@pc001 soft]$ ps -ef|grep postgres root 3397 1603 0 08:54 pts/0 00:00:00 su - postgres postgres 3398 3397 0 08:54 pts/0 00:00:00 -bash postgres 5796 3398 0 09:00 pts/0 00:00:00 psql root 32590 29371 0 10:15 pts/1 00:00:00 su - postgres postgres 32591 32590 0 10:15 pts/1 00:00:00 -bash postgres 288775 1 0 22:13 ? 00:00:00 /usr/postgres/16.1/bin/postgres postgres 288776 288775 0 22:13 ? 00:00:00 postgres: checkpointer postgres 288777 288775 0 22:13 ? 00:00:00 postgres: background writer postgres 288779 288775 0 22:13 ? 00:00:00 postgres: walwriter postgres 288780 288775 0 22:13 ? 00:00:00 postgres: autovacuum launcher postgres 288781 288775 0 22:13 ? 00:00:00 postgres: logical replication launcher postgres 289832 32591 0 22:16 pts/1 00:00:00 ps -ef postgres 289833 32591 0 22:16 pts/1 00:00:00 grep --color=auto postgres
  • 查看 postgresql 运行的端口号

    # 方式一:从以下输出可看出端口号为默认值:5432 [postgres@pc001 soft]$ netstat -a|grep PGSQL unix 2 [ ACC ] STREAM LISTENING 362597 /tmp/.s.PGSQL.5432 # 方式二: [postgres@pc001 soft]$ ss -tnlp|grep post LISTEN 0 200 0.0.0.0:5432 0.0.0.0:* users:(("postgres",pid=288775,fd=6)) LISTEN 0 200 [::]:5432 [::]:* users:(("postgres",pid=288775,fd=7))
最后修改时间:2024-10-15 22:47:28
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论