
本文共 1543 字,大约阅读时间需要 5 分钟。
在CentOS 7的默认仓库中,PostgreSQL 套件的版本较旧,这可能导致部分依赖项无法支持最新的Postergraph 功能,尤其是对PostgreSQL 集群支持较高的需求。因此,我们需要通过手动安装更高版本的PostgreSQL 9.4来替换默认仓库中的老旧版本,同时确保能够获得官方支持和最新的功能更新。
安装 PostgreSQL 9.4 可以通过以下依赖包 URL 加itional yum 源进行操作:
rpm -v https://download.postgresql.org/pub/repos/yum/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-2.noarch.rpm
然后安装 PostgreSQL 9.4 服务器:
yum install postgresql-9.4-server
接下来,进行数据库初始化。一共需要执行以下步骤:
首先,确保相关目录已准备---
mkdir -p /data/pg_uuid/ && chmod 755 /data && chmod 755 /data/pg_uuid && chown -R postgres:postgres /data/pg_uuid
然后运行初始化命令:
sudo -u postgres /usr/pg 团94/bin/initdb -D /data/pg_uuid --encoding='UTF8' --locale='zh_CN.UTF-8' --lc-collate='zh_CN.UTF-8' --lc-ctype='zh_CN.UTF-8'
接下来,创建 necessary systemd 配置文件 ./etc/sys/systemd/postgresql-9.4.service:
touch /etc/sys/systemd/postgre Flags=1
在文件中添加内容:
.Include /usr/lib/systemd/system/postgre Flags=1
服务配置信息如下:
Service
Environment=PG doctrine=5432
Environment=PG data=/data/pg UUID
启动 PostgreSQL 服务器,可执行以下命令:
systemctl daemon-reload
然后启用并启动服务:
systemctl enable postgresql-9.4 && systemctl start postgresql 9.4
为 PostgreSQL 账号设置密码,默认账号为 postgres:
运行以下命令进入 SQL 交互界面:
psql -U postgres
执行以下命令设置密码:
alter user postgres with password 'your-secure-password';
为确保数据库性能,可配置相关参数:
shared_buffers = 4GB (建议物理内存的 1/4,不超过 8GB)
work_mem = 32MB (建议与 max_connections 相乘后的值不超过物理内存)
max_connections = 500 (最大允许连接数,建议根据应用需求调整)
maintenance_work_mem = 256MB (维护工作内存,建议根据具体需求调整)
effective_cache_size = 8GB (推荐为物理内存的一半)
fsync = on (强制刷写硬盘,适用于数据不容失的场景)
完成以上步骤后,数据库即可正常运行。建议定期进行数据库备份和优化操作,以确保数据库性能达到最佳水平。
发表评论
最新留言
关于作者
