postgresql-安装过程
https://www.hyouit.com?aff=418
1、初始化系统配置
# useradd -d /opt/postgres postgres
# yum groupinstall -y "Development Tools" "Legacy UNIX Compatibility" -y
# yum install -y bison flex readline* zlib-devel gcc* gmake -y
# mkdir /pgdata
# mkdir /archive
# chown postgres.postgres /pgdata/ -R
# chown postgres.postgres /archive/ -R
# vim /etc/sysctl.conf
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmmni = 4096
kernel.sem = 50100 64128000 50100 1280
fs.file-max = 7672460
net.ipv4.ip_local_port_range = 9000 65000
net.core.rmem_default = 1048576
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
# sysctl -p
# vim /etc/security/limits.conf
* soft nofile 131072
* hard nofile 131072
* soft nproc 131072
* hard nproc 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000
2、安装postgresql数据库
# tar -zxvf postgresql-12.6.tar.gz
# cd postgresql-12.6
# ./configure --prefix=/opt/postgres/ --with-pgport=1921
# gmake world
# gmake install-world
# chown postgres.postgres /opt/postgres/ -R
# su - postgres
$ vim .bash_profile
export PGDATA=/pgdata
export PGHOME=/opt/postgres
export LD_LIBRARY_PATH=${PGHOME}/lib:${LD_LIBRARY_PATH}
export DATE=$(date +"%y%m%d%H%M")
export PATH=${PGHOME}/bin:${PATH}
export MANPATH=${PGHOME}/share/man:${MANPATH}
export PGUSER=postgres
$ source .bash_profile
$ psql --version
## 初始化数据
$ initdb -A md5 -D ${PGDATA} -E utf8 --locale=C -W
## 启动数据库
$ pg_ctl -D /pgdata -l logfile start
$ psql
Password for user postgres:
psql (12.6)
Type "help" for help.
## 停止数据库
$ pg_ctl -D /pgdata/12/data/ stop -ms # 等用户连接主动关闭后,再停止
$ pg_ctl -D /pgdata/12/data/ stop -mf # 默认方式,系统断开用户连接后停止
$ pg_ctl -D /pgdata/12/data/ stop -mi # 直接强制停止
$ pg_ctl restart -mf
3、简单操作
postgres=# create database test;
postgres=# \c test
test=# create table t1(id int);
test=# insert into t1 values(1);
test=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+---------+-------+-----------------------
postgres | postgres | UTF8 | C | C |
template0 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
test | postgres | UTF8 | C | C |
test=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+----------
public | t1 | table | postgres
test=# \d+
List of relations
Schema | Name | Type | Owner | Size | Description
--------+------+-------+----------+------------+-------------
public | t1 | table | postgres | 8192 bytes |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现