PostgreSQL安装
Berkley Postgres Project
PostgreSQL
官网网站:http://postgresql.org/download/linux/redhat
基础信息:
OS: Rocky Linux - rocky8.7
PgSQL version: 13.6
检查防火墙 systemctl status firewalld
PgSQL
# Install the repository RPM:
sudo dnf install -y \
https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
# Disable the built-in PostgreSQL module:
sudo dnf -qy module disable postgresql
# Install PostgreSQL:
sudo dnf install -y postgresql13-server
# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
检查
systemctl status postgresql-13
systemctl status mysqld
提供外部接口
cat /etc/passwd 有这个postgres用户
#su - postgres
su postgres
whoami 【这个用户不需要密码】
#进入数据库
psql
修改postgresql的密码
ALTER USER postgres WITH PASSWORD 'xxx';
登录
psql -h localhost -p 5432 -U postgres
>Password for user postgres:
cd /var/lib/pgsql/13/data/
>* pg_hba.conf
>* postgresql.conf
pg_hba.conf
86 # IPv4 local connections
87 host all all 0.0.0.0/0 scram-sha-256
88 # Allow access remote to login
postgresql.conf
60 listen_addresses = '*'
postgresql常用命令
# 重启服务
systemctl restart postgresql-13
# 访问数据库
psql -h localhost -p 5432 -U postgres
# 创建数据库
CREATE DATABASE my_db;
# 选中数据库
\c my_db
# 建表
CREATE TABLE t_user(
id INT PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
age INT NOT NULL,
gender CHAR(10),
salary REAL
);
# 查询
select * from t_user;

配置文件参考文献:
https://www.postgresql.org/docs/11/runtime-config-connection.html#RUNTIME-CONFIG-CONNECTION-SETTINGS
注意:对应的版本不支持网页打开,需要下载到本地
https://www.postgresql.org/docs/release/13.6/
3817

被折叠的 条评论
为什么被折叠?



