記一次 Centos7 PostgreSql 數據庫安裝擴展

一、數據庫搭建

1、yum 指定目錄安裝

https://blog.csdn.net/llwy1428/article/details/105143053

2、yum 直接安裝

https://blog.csdn.net/llwy1428/article/details/102486414

3、編譯安裝

https://blog.csdn.net/llwy1428/article/details/95444151

4、PostgreSql 基本操作

https://blog.csdn.net/llwy1428/article/details/102598732

二、擴展安裝

1、下載 epel-7.repo


[root@pgadmin ~]# cd /etc/yum.repos.d/
[root@pgadmin yum.repos.d]# wget https://mirrors.aliyun.com/repo/epel-7.repo

2、安裝工具

[root@localhost ~]# yum install pgagent_11 postgis25_11 -y

3、查看當前服務器可用的 Extension 擴展列表

# 切換用戶
[root@localhost ~]# su - postgres
Last login: Mon Mar 16 21:15:46 CST 2020 on pts/3
# 進入 postgresql 命令行
[postgres@localhost ~]$ psql
psql (11.5)
Type "help" for help.

postgres=# select name from pg_available_extensions;
             name             
------------------------------
 insert_username
 dict_int
 adminpack
 amcheck
 intagg
 autoinc
 intarray
 bloom
 file_fdw
 dblink
 btree_gin
 fuzzystrmatch
 seg
 btree_gist
 jsonb_plperl
 hstore
 citext
 isn
 jsonb_plperlu
 cube
 hstore_plperl
 dict_xsyn
 hstore_plperlu
 earthdistance
 lo
 ltree
 pg_trgm
 tcn
 moddatetime
 pageinspect
 pg_visibility
 pgstattuple
 postgres_fdw
 pg_buffercache
 xml2
 pg_freespacemap
 refint
 sslinfo
 tablefunc
 pg_prewarm
 pgcrypto
 pg_stat_statements
 pgrowlocks
 timetravel
 tsm_system_rows
 address_standardizer
 tsm_system_time
 unaccent
 address_standardizer_data_us
 uuid-ossp
 postgis
 postgis_sfcgal
 postgis_tiger_geocoder
 postgis_topology
 plpgsql
(55 rows)

4、查看當前數據庫列表

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

5、在默認數據庫中安裝 pgagent 擴展

postgres=# create extension pgagent;
CREATE EXTENSION

安裝擴展成功

服務啓動、關閉、設置開機啓動

服務啓動
[root@localhost ~]# systemctl start pgagent_11
服務停止
[root@localhost ~]# systemctl stop pgagent_11
服務當前狀態查看
[root@localhost ~]# systemctl status pgagent_11
服務開機啓動
[root@localhost ~]# systemctl enable pgagent_11
禁止服務開機啓動
[root@localhost ~]# systemctl disable pgagent_11

6、在指定數據庫中 安裝擴展

(1)創建測試數據庫,並查看列表

postgres=# create database pgtest;
CREATE DATABASE
postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 pgtest    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

(2)切換數據庫

postgres=# \c pgtest
You are now connected to database "pgtest" as user "postgres".
pgtest=#

(3)安裝擴展  postgis

pgtest=# create extension "uuid-ossp";
CREATE EXTENSION

(4)安裝擴展  uuid-ossp

pgtest=# create extension postgis;
CREATE EXTENSION

(5)安裝擴展  ltree

pgtest=# create extension "ltree";
CREATE EXTENSION

(6)安裝擴展  timetravel

pgtest=# create extension "timetravel";
CREATE EXTENSION

其他擴展:略。

(7)查看當前已安裝的擴展

pgtest=# \dx
                                      List of installed extensions
    Name    | Version |   Schema   |                             Description                             
------------+---------+------------+---------------------------------------------------------------------
 ltree      | 1.1     | public     | data type for hierarchical tree-like structures
 plpgsql    | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis    | 2.5.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
 timetravel | 1.0     | public     | functions for implementing time travel
 uuid-ossp  | 1.1     | public     | generate universally unique identifiers (UUIDs)
(5 rows)

(8)刪除Extension擴展,查看結果

pgtest=# drop extension timetravel;
DROP EXTENSION
pgtest=# \dx
                                      List of installed extensions
   Name    | Version |   Schema   |                             Description                             
-----------+---------+------------+---------------------------------------------------------------------
 ltree     | 1.1     | public     | data type for hierarchical tree-like structures
 plpgsql   | 1.0     | pg_catalog | PL/pgSQL procedural language
 postgis   | 2.5.3   | public     | PostGIS geometry, geography, and raster spatial types and functions
 uuid-ossp | 1.1     | public     | generate universally unique identifiers (UUIDs)
(4 rows)

 

至此,Centos7  PostgreSql  數據庫安裝插件基本操作完畢!

希望能夠對您有所幫助!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章