postgresql源码编译

一、环境说明

$ lsb_release  -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic
  • 安装docker
$ sudo apt install docker.io

$ sudo docker  -v
Docker version 20.10.7, build 20.10.7-0ubuntu5~18.04.3
  • 获取ubuntu镜像
$ sudo docker pull ubuntu

二、编译

2.1 获取源码

  • 从官网上下载源码
$ wget https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.bz2
  • 解压
$ tar xf postgresql-14.2.tar.bz2

2.2 编译源码

  • 启动容器
$ sudo docker run -it  -v /home/trevor/桌面/postgresql-14.2:/code --name build-pg ubuntu /bin/bash

root@2f9d6ce41c2b:/# cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

  • 安装编译工具
root@2f9d6ce41c2b:/# apt update && apt install -y gcc libreadline-dev zlib1g-dev make
  • 编译
root@2f9d6ce41c2b:/# cd /code
root@2f9d6ce41c2b:/# ./configure 
root@2f9d6ce41c2b:/# make 
root@2f9d6ce41c2b:/# make install

2.3 初始化

  • 创建postgres用户
root@2f9d6ce41c2b:/# adduser postgres
root@2f9d6ce41c2b:/# mkdir /usr/local/pgsql/data
root@2f9d6ce41c2b:/# chown postgres /usr/local/pgsql/data
root@2f9d6ce41c2b:/# su - postgres
  • 初始化db
postgres@2f9d6ce41c2b:~$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
  • 启动服务器
postgres@2f9d6ce41c2b:~$ /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

三、验证

3.1 创建数据库

postgres@2f9d6ce41c2b:~$ /usr/local/pgsql/bin/createdb test

3.2 使用数据库

postgres@2f9d6ce41c2b:~$ /usr/local/pgsql/bin/psql test
psql (14.2)
Type "help" for help.

test=# select version();
 version                            
--------------------------------------------------------------------------------------------------
 PostgreSQL 14.2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, 64-bit
(1 row)

你可能感兴趣的:(pg,postgresql)