PostgreSQL版本与其对应支持的python3版本
PostgreSQL VersionPython Version9.X3.310.X3.411.X3.6 将python3.6对应的plpython3.so 文件添加到/usr/pgsql-11/lib/中 [root@localhost ~]# wget -c https://gitee.com/CodeForLive/PGEnablePlpython3/raw/master/py36/plpython3.so -C /usr/pgsql-11/lib plpython3.so 100% 143KB 9.9MB/s 00:00 [root@localhost ~]# chmod 755 /usr/pgsql-11/lib/plpython3.so 初始化数据库 [root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb数据库文件一般在/var/lib/pgsql/11/目录下 6. 启动PostgreSQL服务
[root@localhost ~]# systemctl start postgresql-11 && systemctl status postgresql-11 ● postgresql-11.service - PostgreSQL 11 database server Loaded: loaded (/usr/lib/systemd/system/postgresql-11.service; disabled; vendor preset: disabled) Active: active (running) since Fri 2019-05-17 14:27:53 CST; 14ms ago Docs: https://www.postgresql.org/docs/11/static/ Process: 14099 ExecStartPre=/usr/pgsql-11/bin/postgresql-11-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS) Main PID: 14106 (postmaster) Tasks: 8 CGroup: /system.slice/postgresql-11.service ├─14106 /usr/pgsql-11/bin/postmaster -D /var/lib/pgsql/11/data/ ├─14107 postgres: logger ├─14109 postgres: checkpointer ├─14110 postgres: background writer ├─14111 postgres: walwriter ├─14112 postgres: autovacuum launcher ├─14113 postgres: stats collector └─14114 postgres: logical replication launcher May 17 14:27:53 localhost.localdomain systemd[1]: Starting PostgreSQL 11 database server... May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.839 CST [14106] LOG: listening on IPv6 addr... 5432 May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.839 CST [14106] LOG: listening on IPv4 addr... 5432 May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.841 CST [14106] LOG: listening on Unix sock...5432" May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.843 CST [14106] LOG: listening on Unix sock...5432" May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.860 CST [14106] LOG: redirecting log output...ocess May 17 14:27:53 localhost.localdomain postmaster[14106]: 2019-05-17 14:27:53.860 CST [14106] HINT: Future log output wil...log". May 17 14:27:53 localhost.localdomain systemd[1]: Started PostgreSQL 11 database server. Hint: Some lines were ellipsized, use -l to show in full. 设置为开机启动 [root@localhost ~]# systemctl enable postgresql-11 Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service. 登陆postgreSQl 并修改密码 [root@localhost ~]# su - postgres -bash-4.2$ psql psql (11.3) Type "help" for help. postgres=# \password Enter new password: Enter it again: 查看plpython3 是否可以使用 postgres=# create language plpython3u; CREATE LANGUAGE postgres=# CREATE FUNCTION pymax (a integer, b integer) postgres-# RETURNS integer postgres-# AS $$ postgres$# if a > b: postgres$# return a postgres$# return b postgres$# $$ LANGUAGE plpython3u; CREATE FUNCTION postgres=# select pymax(20,12); pymax ------- 20 (1 row) postgres=# select pymax(10,12); pymax ------- 12 (1 row) 设置远程连接 修改postgresql.conf 文件 [root@localhost ~]# vim /var/lib/pgsql/11/data/postgresql.conf 59 listen_addresses = '*' # what IP address(es) to listen on; 60 # comma-separated list of addresses; 61 # defaults to 'localhost'; use '*' for all 62 # (change requires restart) 63 #port = 5432 # (change requires restart) 64 max_connections = 100 # (change requires restart) 65 #superuser_reserved_connections = 3 # (change requires restart) 修改pg_hba.conf文件 最后一行添加 [root@localhost ~]# vim /var/lib/pgsql/11/data/pg_hba.conf host all all 0.0.0.0/0 md5 打开防火墙5432端口并重启postgresql服务 [root@localhost ~]# vim /var/lib/pgsql/11/data/postgresql.conf [root@localhost ~]# vim /var/lib/pgsql/11/data/pg_hba.conf [root@localhost ~]# firewall-cmd --zone=public --add-port=5432/tcp --permanent success [root@localhost ~]# firewall-cmd --reload success 重启postgresql-11 服务并测试 [root@localhost ~]# systemctl restart postgresql-11