Ubuntu安装PostgreSQL
系统环境:
1 2 3 | 操作系统:Ubuntu 16.04 数据库:PostgreSQL 9.3 |
安装PostgreSQL
- 修改apt源
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # vim /etc/apt/sources.list.d/pgdg.list ############################ ## 根据系统版本添加下面这行 ############################ ## 14.04 deb http: //apt .postgresql.org /pub/repos/apt/ trusty-pgdg main ## 16.04 deb http: //apt .postgresql.org /pub/repos/apt/ xenial-pgdg main ## 17.04 deb http: //apt .postgresql.org /pub/repos/apt/ zesty-pgdg main # apt update |
- 安装PostgreSQL
1 2 | ## xxx替换为版本号,此处是9.3 sudo apt install postgresql-xxx |
- 编辑
/etc/postgresql/9.5/main/postgresql.conf
1 2 3 4 5 6 7 8 9 10 | 将下面 listen_addresses = 'localhost' 注释去掉并改为 listen_addresses = '*' # - Connection Settings - #listen_addresses = 'localhost' # what IP address(es) to listen on; # comma-separated list of addresses; # defaults to 'localhost'; use '*' for all ... 将下面password_encryption = on 注释打开 #password_encryption = on |
- 切换用户
1 | su - postgres |
- 通过
psql
命令进入postgresql客户端,修改用户密码:
1 | ALTER USER postgres PASSWORD '123456' ; |
-
修改pg_hba文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # vim /etc/postgresql/9.5/main/pg_hba.conf ################################################################# ## 修改 host all all 192.168.1.0/24 md5 中的ip,为:0.0.0.0/0 ################################################################# # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1 /32 trust host all all 192.168.1.0 /24 md5 # IPv6 local connections: host all all ::1 /128 trust |
- 启动服务:
1 2 | ## 此处xx为9.3 sudo systemctl start postgresql@xx-main.service |
博客参考链接
1 2 3 | https: //blog .csdn.net /ax7399/article/details/78210051 https: //www .jianshu.com /p/dda94c4ffd52 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· Vue3状态管理终极指南:Pinia保姆级教程