75 字
1 分钟
PostgreSQL 远程访问与数据目录迁移
尚未安装 PostgreSQL?参见 PostgreSQL 安装指南
一、配置远程访问
1. 修改认证方式
# 将 host 连接的认证方式从 ident 改为 md5(密码认证)sudo sed -i '/^host/s/ident/md5/' /etc/postgresql/14/main/pg_hba.conf
# 将本地连接的认证方式从 peer 改为 trustsudo sed -i '/^local/s/peer/trust/' /etc/postgresql/14/main/pg_hba.conf2. 允许任意 IP 连接
编辑 /etc/postgresql/14/main/pg_hba.conf,添加:
# 允许所有 IP 使用密码连接host all all 0.0.0.0/0 md53. 监听所有网络接口
编辑 /etc/postgresql/14/main/postgresql.conf,取消注释并修改:
listen_addresses = '*'4. 重启服务
sudo systemctl restart postgresqlsudo systemctl enable postgresql二、数据目录迁移
# 1. 停止服务systemctl stop postgresql
# 2. 拷贝数据到新目录cp -rf /var/lib/postgresql/14/main /opt/postgresql/
# 3. 设置权限chown -R postgres:postgres /opt/postgresql/chmod 700 /opt/postgresql/
# 4. 修改配置文件中的数据目录vim /etc/postgresql/14/main/postgresql.conf# 修改:data_directory = '/opt/postgresql/main'
# 5. 启动服务systemctl start postgresql
# 6. 验证psql -U postgres -c 'SHOW data_directory;' 分享
如果这篇文章对你有帮助,欢迎分享给更多人!
PostgreSQL 远程访问与数据目录迁移
https://blog.olinl.com/posts/postgresql-config/ 相关文章 智能推荐
1
PostgreSQL 安装指南(Ubuntu / Docker)
服务与应用运维 介绍在 Ubuntu 上二进制安装 PostgreSQL 14 及使用 Docker Compose 部署的方式,包括修改数据目录和密码等基础配置。
2
PostgreSQL 外部表(FDW)跨库查询配置
服务与应用运维 使用 postgres_fdw 扩展配置 PostgreSQL 外部数据包装器,实现跨数据库实例的表查询,解决 PostgreSQL 不支持跨库查询的限制。
3
PostgreSQL 备份与恢复
服务与应用运维 介绍使用 pg_dumpall 和 pg_dump 对 PostgreSQL 进行全量备份与单表备份,以及在实体机和 Docker 容器中的恢复方法。
4
CentOS 安装 MongoDB 3.4 并配置认证
服务与应用运维 在 CentOS 上通过 YUM 仓库安装 MongoDB 3.4,配置外部访问与用户密码认证,适合内网开发环境快速搭建。
5
CentOS 编译安装 Redis 6.2 并配置 Systemd 服务
服务与应用运维 从源码编译安装 Redis 6.2,配置密码、外部访问与后台运行,并注册为 systemd 服务实现开机自启。
