– 近期需要学习postgis,首先,源码编译一个postgresql
依赖安装
- yum源为阿里云镜像
[root@localhost ~]# yum repolist 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 源标识 源名称 状态 base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 526 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 6,173 repolist: 16,771 [root@localhost ~]#
#pg依赖
yum install -y cmake make gcc-c++ ncurses-devel
yum install -y zlib-devel
yum install -y perl-ExtUtils-Embed
yum install -y gcc
yum install readline-devel
yum install -y pam-devel
yum install -y libxml2-devel
yum install libxslt-devel
yum install python-devel
yum install -y cmake
yum install openssl-devel
yum install openldap-devel
#解压源码用
yum install -y bzip2
新建用户和目录
[root@localhost ~]# useradd postgres [root@localhost ~]# [root@localhost ~]# passwd postgres 更改用户 postgres 的密码 。 新的 密码: 无效的密码: 密码包含用户名在某些地方 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 [root@localhost ~]# [root@localhost opt]# mkdir -pv /opt/pg15/dbms mkdir: 已创建目录 "/opt/pg15" mkdir: 已创建目录 "/opt/pg15/dbms" [root@localhost opt]# [root@localhost pg15]# ll 总用量 231702 drwxr-xr-x 2 root root 6 3月 10 17:17 dbms -rw-r--r-- 1 root root 23170228 3月 8 00:10 postgresql-15.12.tar.bz2 [root@localhost pg15]# chown -Rv postgres:postgres /opt/pg15/ changed ownership of "/opt/pg15/dbms" from root:root to postgres:postgres changed ownership of "/opt/pg15/postgresql-15.12.tar.bz2" from root:root to postgres:postgres changed ownership of "/opt/pg15/" from root:root to postgres:postgres [root@localhost pg15]#
postgres用户环境变量
# 端口,默认5432,可修改
export PGPORT=5432
# PG软件安装路径
export PG_HOME=/opt/pg15/dbms
# bin
export PATH=$PG_HOME/bin:$PATH
# 数据目录
export PGDATA=/opt/pg15/data
# 库文件指针
export LD_LIBRARY_PATH=$PG_HOME/lib
# 操作系统语言集,可选
export LANG=en_US.utf8
源码编译安装过程三板斧
- configure
- make
- make install
tar -xvf postgresql-15.12.tar.bz2 [postgres@localhost ~]$ cd /opt/pg15/postgresql-15.12/ [postgres@localhost postgresql-15.12]$ ll total 1272 -rw-r--r-- 1 postgres postgres 1192 Feb 18 05:14 COPYRIGHT -rw-rw-r-- 1 postgres postgres 4264 Mar 10 17:27 GNUmakefile -rw-r--r-- 1 postgres postgres 4264 Feb 18 05:14 GNUmakefile.in -rw-r--r-- 1 postgres postgres 277 Feb 18 05:14 HISTORY -rw-r--r-- 1 postgres postgres 63842 Feb 18 05:27 INSTALL -rw-r--r-- 1 postgres postgres 1875 Feb 18 05:14 Makefile -rw-r--r-- 1 postgres postgres 1213 Feb 18 05:14 README -rw-r--r-- 1 postgres postgres 397 Feb 18 05:14 aclocal.m4 drwxrwxr-x 2 postgres postgres 4096 Feb 18 05:26 config -rw-rw-r-- 1 postgres postgres 438964 Mar 10 17:27 config.log -rwxrwxr-x 1 postgres postgres 40252 Mar 10 17:27 config.status -rwxr-xr-x 1 postgres postgres 608068 Feb 18 05:14 configure -rw-r--r-- 1 postgres postgres 90975 Feb 18 05:14 configure.ac drwxrwxr-x 61 postgres postgres 4096 Feb 18 05:26 contrib drwxrwxr-x 3 postgres postgres 87 Feb 18 05:26 doc drwxrwxr-x 16 postgres postgres 4096 Mar 10 17:27 src [postgres@localhost postgresql-15.12]$ [postgres@localhost postgresql-15.12]$ ./configure --prefix=/opt/pg15/dbms ... ... [postgres@localhost postgresql-15.12]$ make && make install ... ... [postgres@localhost postgresql-15.12]$
初始化与启动服务
- 初始化 initdb -U postgres -D /opt/pg15/data
- 启动服务 pg_ctl -D /opt/pg15/data -l logfile start
[postgres@localhost pg15]$ ll total 53904 drwxr-xr-x 6 postgres postgres 56 Mar 10 17:38 dbms -rw-r--r-- 1 postgres postgres 17058464 Mar 9 15:48 gdal300.zip -rw-r--r-- 1 postgres postgres 14960460 Mar 9 14:51 postgis-3.4.4.tar.gz drwxrwxr-x 6 postgres postgres 4096 Mar 10 17:27 postgresql-15.12 -rw-r--r-- 1 postgres postgres 23170228 Mar 8 00:10 postgresql-15.12.tar.bz2 [postgres@localhost pg15]$ [postgres@localhost pg15]$ initdb -U postgres -D /opt/pg15/data The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. creating directory /opt/pg15/data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Asia/Shanghai creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: pg_ctl -D /opt/pg15/data -l logfile start [postgres@localhost pg15]$ [postgres@localhost pg15]$ ll total 53908 drwx------ 19 postgres postgres 4096 Mar 10 17:41 data drwxr-xr-x 6 postgres postgres 56 Mar 10 17:38 dbms -rw-r--r-- 1 postgres postgres 17058464 Mar 9 15:48 gdal300.zip -rw-r--r-- 1 postgres postgres 14960460 Mar 9 14:51 postgis-3.4.4.tar.gz drwxrwxr-x 6 postgres postgres 4096 Mar 10 17:27 postgresql-15.12 -rw-r--r-- 1 postgres postgres 23170228 Mar 8 00:10 postgresql-15.12.tar.bz2 [postgres@localhost pg15]$ [postgres@localhost pg15]$ pg_ctl -D /opt/pg15/data -l logfile start waiting for server to start.... done server started [postgres@localhost pg15]$ [postgres@localhost pg15]$
登录检查
[postgres@localhost pg15]$ psql psql (15.12) Type "help" for help. postgres=# select version(); version ---------------------------------------------------------------------------------------------------------- PostgreSQL 15.12 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit (1 row) postgres=# \l+ List of databases Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges | Size | Tablespace | Description -----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------+---------+------------+-------------------------------------------- postgres | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 | | libc | | 7429 kB | pg_default | default administrative connection database template0 | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 | | libc | =c/postgres +| 7273 kB | pg_default | unmodifiable empty database | | | | | | | postgres=CTc/postgres | | | template1 | postgres | UTF8 | en_US.utf-8 | en_US.utf-8 | | libc | =c/postgres +| 7273 kB | pg_default | default template for new databases | | | | | | | postgres=CTc/postgres | | | (3 rows) postgres=# \du+ List of roles Role name | Attributes | Member of | Description -----------+------------------------------------------------------------+-----------+------------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} | postgres=# show data_directory; data_directory ---------------- /opt/pg15/data (1 row) postgres=# \q [postgres@localhost pg15]$
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




