PostgreSQL源码安装 Installation from Source Code
CentOS redhat linux:
Download source:
a.解压源码.
tar -zxvf postgresql-14.0.tar.gz -C /opt
b.cd到刚解压的目录
cd /opt/postgresql-14.0/
c.安装依赖包:
yum install readline-devel zlib-devel flex bison
yum install c++ gcc readline readline-devel zlib zlib-devel
d.checking 是否安装编译等环境是否OK,并指定要安装的路径。
./configure --prefix=/var/lib/pgsql/14
e.构建编译
make
/opt/postgresql-14.0/src/test/regress/log/initdb.log
f.make check
g.install 安装与清除compiler file.
make install
make clean --make distclean
h.stop old postgresql:
systemctl stop postgresql-11
i.mkdir path
mkdir /var/lib/pgsql/14/pgsqldata
chown -R postgres:postgres /var/lib/pgsql/14/
j.initially database:初始化数据库
/var/lib/pgsql/14/bin/initdb -D /var/lib/pgsql/14/pgsqldata
k.启动数据库实例
--/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/pgsqldata -l logfile start
su - postgres --要到postgres account.
/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/pgsqldata start
/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/pgsqldata status --查看状态.
L.create database
/var/lib/pgsql/14/bin/psql
/var/lib/pgsql/14/bin/createdb databasename
--把postgres帐号的密码改为想要的密码:
alter user postgres with password 'postgres';
M.startup 开机启动设置
vi /usr/lib/systemd/system/postgresql-14.service
--输入如下信息:
[Unit]
Description=postgreSQL Server
[Service]
User=postgres
Group=postgres
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/pgsqldata start
LimitNOFILE = 65535
Restart=on-failure
RestartSec=3
RestartPreventExitStatus=1
PrivateTmp=false
[Install]
WantedBy=multi-user.target
M2.重新加载或重启server
systemctl daemon-reload
systemctl start postgresql-14
systemctl enable postgresql-14
N.远程登录配置 setting remote login:pg_hba.conf 与 postgresql.conf文件
# vi /var/lib/pgsql/14/pg_hba.conf
host all all 0.0.0.0/0
# vi /var/lib/pgsql/14/postgresql.conf
listen_addresses = '*'
O.data_directory tree:
show data_directory;
database_file数据库文件存放在:base,如/var/lib/pgsql/14/pgsqldata/base;
每个数据库都有一个ID,文件夹名称是按照database ID号命名,data_file就存在对应的database ID号下面。不像Oracle是按照database name命名。
Y.uninstall
./configure --prefix=/var/lib/pgsql
make uninstall
Z.Official command:
./configure
make
su
make install
adduser postgres
mkdir /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
Installation from Source Code offial url:https://www.postgresql.org/docs/current/install-requirements.html
Refer:https://www.cnblogs.com/wsum/p/15522211.html
http://blog.itpub.net/7569309/viewspace-2724945/
Ubuntu linux install from source code:
tar -zxvf postgresql-14.0.tar.gz -C /opt
cd /opt/postgresql-14.0/
c.安装依赖包:
sudo apt-get install gcc
sudo apt install libreadline-dev
sudo apt install zlib1g-dev
d.checking 是否安装编译等环境是否OK,并指定要安装的路径。
./configure --prefix=/var/lib/pgsql/14
e.构建编译
sudo apt install make #--install make first.
make
make world
f.make check
make check
g.install 安装与清除compiler file.
make install
make clean --make distclean
i.mkdir path
mkdir /var/lib/pgsql/14/data
chown -R postgres:postgres /var/lib/pgsql/14/
j.initially database:初始化数据库
/var/lib/pgsql/14/bin/initdb -D /var/lib/pgsql/14/data
k.启动数据库实例
--/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/pgsqldata -l logfile start
su - postgres --要到postgres account.
/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/data start
/var/lib/pgsql/14/bin/pg_ctl -D /var/lib/pgsql/14/data status --查看状态.
L.create database
/var/lib/pgsql/14/bin/createdb databasename
/var/lib/pgsql/14/bin/psql databasename
\l
select version();