centos7上安装postgresql11 Beta2版

本文详细介绍了如何从源代码安装并配置PostgreSQL数据库,包括下载安装包、解压编译、创建用户组和用户、建立数据文件目录、初始化数据库、修改配置文件、启动数据库以及验证数据库是否成功启动。

1.下载安装包

https://ftp.postgresql.org/pub/source/v11beta2/postgresql-11beta2.tar.gz

2.解压编译

tar -zxvf postgresql-11beta2.tar.gz

configure

make

make install

3.生成postgres组和用户

[root@localhost usr]# groupadd postgres
[root@localhost usr]# useradd -g postgres postgres
[root@localhost usr]# passwd postgres

4.建立数据文件目录

root@localhost bin]# mkdir /usr/pgdata
[root@localhost bin]# chown -R postgres:postgres /usr/pgdata
[root@localhost bin]# chmod 700 /usr/pgdata

5.初始化数据库

[postgres@localhost bin]$ ./initdb -D /usr/pgdata/
The files belonging to this database system will be owned by user “postgres”.
This user must also own the server process.

The database cluster will be initialized with locale “en_US.UTF-8”.
The default database encoding has accordingly been set to “UTF8”.
The default text search configuration will be set to “english”.

Data page checksums are disabled.

fixing permissions on existing directory /usr/pgdata … ok
creating subdirectories … ok
selecting default max_connections … 100
selecting default shared_buffers … 128MB
selecting dynamic shared memory implementation … posix
creating configuration files … ok
running bootstrap script … ok
performing post-bootstrap initialization … ok
syncing data to disk … ok

WARNING: enabling “trust” authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
–auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

./pg_ctl -D /usr/pgdata/ -l logfile start

6.修改配置文件

vim postgresql.conf

listen_addresses = ‘*’

port = 5432

7.启动数据库

[postgres@localhost bin]$ ./pg_ctl start -D /usr/pgdata/
waiting for server to start…2018-08-07 10:18:44.704 CST [15690] LOG: listening on IPv4 address “0.0.0.0”, port 5432
2018-08-07 10:18:44.704 CST [15690] LOG: listening on IPv6 address “::”, port 5432
2018-08-07 10:18:44.707 CST [15690] LOG: listening on Unix socket “/tmp/.s.PGSQL.5432”
2018-08-07 10:18:44.869 CST [15700] LOG: database system was shut down at 2018-08-07 10:14:35 CST
2018-08-07 10:18:44.903 CST [15690] LOG: database system is ready to accept connections
done
server started
[postgres@localhost bin]$

8.验证

[postgres@localhost bin]$ ./psql
psql (11beta2)
Type “help” for help.

postgres=# select version();
version

PostgreSQL 11beta2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit
(1 row)

postgres=#

PostgreSQL 17.4.1 尚未发布(截至2025年4月,PostgreSQL 最新稳定本为 **PostgreSQL 16.x**,官方尚未发布 PostgreSQL 17),因此目前无法正式安装 PostgreSQL 17.4.1。可能是你误写了本号,或指的是未来的开发本。 不过,我可以为你提供在主流 Linux 系统(如 Ubuntu/Debian 或 CentOS/RHEL)上安装和配置最新可用的 PostgreSQL 的通用方法,并说明如何从源码安装开发本(如你确实需要测试 PostgreSQL 17 的开发)。 --- ### ✅ 场景一:安装官方最新稳定 PostgreSQL(以 Ubuntu 为例) #### 安装步骤(Ubuntu 22.04 / 24.04) ```bash # 1. 更新系统包 sudo apt update # 2. 安装必要的依赖 sudo apt install -y wget ca-certificates gnupg # 3. 添加 PostgreSQL 官方 APT 源 wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list # 4. 更新包列表 sudo apt update # 5. 安装 PostgreSQL 16(当前最新稳定) sudo apt install -y postgresql-16 postgresql-client-16 # 6. 启动并启用开机自启 sudo systemctl enable postgresql sudo systemctl start postgresql ``` --- ### 🔧 配置 PostgreSQL #### 1. 切换到 `postgres` 用户并进入 psql ```bash sudo -u postgres psql ``` #### 2. 设置 `postgres` 用户密码 ```sql ALTER USER postgres PASSWORD 'your_secure_password'; ``` #### 3. 允许远程连接(可选) 编辑主配置文件: ```bash sudo nano /etc/postgresql/16/main/postgresql.conf ``` 修改以下参数: ```conf listen_addresses = '*' # 允许所有IP连接(生产环境建议指定IP) port = 5432 ``` 配置客户端认证: ```bash sudo nano /etc/postgresql/16/main/pg_hba.conf ``` 添加一行允许远程登录(例如来自 192.168.1.0/24 网段): ```conf # TYPE DATABASE USER ADDRESS METHOD host all all 192.168.1.0/24 md5 ``` #### 4. 重启服务使配置生效 ```bash sudo systemctl restart postgresql ``` #### 5. 开放防火墙(如果使用 ufw) ```bash sudo ufw allow 5432/tcp ``` --- ### 🛠️ 场景二:如果你真的想尝试 PostgreSQL 17(开发) > ⚠️ 注意:这是开发本,不稳定,仅用于测试! #### 从源码编译安装 PostgreSQL 17(开发) ```bash # 1. 安装编译依赖 sudo apt install -y build-essential libreadline-dev zlib1g-dev bison flex # 2. 克隆官方 Git 仓库(包含 pg17 分支) git clone https://github.com/postgres/postgres.git cd postgres # 查看是否有 PG17 分支(通常是 maint分支 或 特定标签) git branch -r | grep REL17 # 假设存在 REL17 标签(实际可能还未打 tag) git checkout REL17_0_BETA1 # 示例,具体名称需查证 # 3. 配置编译选项 ./configure --prefix=/usr/local/pgsql --enable-debug # 4. 编译并安装 make -j$(nproc) sudo make install # 5. 创建用户和数据目录 sudo useradd -m -s /bin/bash postgres sudo mkdir /usr/local/pgsql/data sudo chown postgres:postgres /usr/local/pgsql/data # 6. 初始化数据库 sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data # 7. 启动数据库 sudo -u postgres /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start # 8. 连接测试 sudo -u postgres /usr/local/pgsql/bin/psql ``` --- ### ✅ 验证安装成功 ```bash psql -U postgres -h localhost -c "SELECT version();" ``` 输出应包含类似: ``` PostgreSQL 16.3 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit ``` --- ### ❗注意事项 - **PostgreSQL 17 目前未正式发布**,不建议用于生产。 - 使用官方 APT/YUM 源可以确保自动更新和安全补丁。 - 生产环境中请限制 `pg_hba.conf` 的访问来源,使用强密码或证书认证。 - 考虑使用 `pgAdmin` 或 `DBeaver` 图形化管理工具。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值