Mac13编译安装Postgres15.2及初始化配置笔记
Postgres官网下载postgresql-15.2源代码。
参考源码文件INSTALL文件进行安装及初始化:
Short Version
./configure
make
su
make install
adduser postgres
mkdir -p /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
The long version is the rest of this document.
部分过程记录
(按默认命令)安装pgsql后,部分命令安装位置:
/bin/sh ../../../config/install-sh -c -d '/usr/local/pgsql/bin'
/usr/bin/install -c createdb '/usr/local/pgsql/bin'/createdb
/usr/bin/install -c dropdb '/usr/local/pgsql/bin'/dropdb
/usr/bin/install -c createuser '/usr/local/pgsql/bin'/createuser
/usr/bin/install -c dropuser '/usr/local/pgsql/bin'/dropuser
/usr/bin/install -c clusterdb '/usr/local/pgsql/bin'/clusterdb
/usr/bin/install -c vacuumdb '/usr/local/pgsql/bin'/vacuumdb
/usr/bin/install -c reindexdb '/usr/local/pgsql/bin'/reindexdb
/usr/bin/install -c pg_isready '/usr/local/pgsql/bin'/pg_isready
若需要指定安装目录,如下命令:
./configure --prefix=/Users/weirdgiser/Documents/Softwares/installed/pgsql
启动pgsql服务:
/usr/local/pgsql/bin/pg_ctl -D /Users/weirdgiser/Data/pgsql15/data -l logfile start
waiting for server to start.... done
创建测试数据库
/usr/local/pgsql/bin/createdb test
连接测试数据库
/usr/local/pgsql/bin/psql test
通过DBeaver连接: 若有多个数据库版本,注意选择合适的客户端
常用命令
\l 列举数据库
\c DB 连接数据库
\d 列举数据表
\q 退出