PostgresQL 安裝環境

2021-10-01 06:47:26 字數 2472 閱讀 3882

到目前為止(2019-08-10),centos7 預設攜帶了9.2.24版本的postgresql,我們可以直接從源進行安裝:

sudo yum install postgresql-server postgresql-contrib

# 初始化資料庫

sudo postgresql-setup initdb

sudo systemctl start postgresql

# 設定為開機自啟動

sudo systemctl enable postgresql

# 重啟服務

systemctl restart postgresql

# 先安裝依賴包

yum -y install libicu libxslt perl-lib systemd-libs

# 按照如下順序安裝好所有的包

[root@node1 opt]# rpm -ivh postgresql11-libs-11.2-1pgdg.rhel7.x86_64.rpm

[root@node1 opt]# rpm -ivh postgresql11-11.2-1pgdg.rhel7.x86_64.rpm

[root@node1 opt]# rpm -ivh postgresql11-contrib-11.2-1pgdg.rhel7.x86_64.rpm

[root@node1 opt]# rpm -ivh postgresql11-server-11.2-1pgdg.rhel7.x86_64.rpm

- 注意:注意離線的安裝方式,版本號會影響相關的檔案路徑。例如 `/var/lib/pgsql` 變成 `/var/lib/pgsql/11` `systemctl status postgresql-11`

- 注意:程式會被按照到 `/usr/pgsql-11/` 這個目錄

# 初始化db

/usr/pgsql-11/bin/postgresql-11-setup initdb

initializing database ... ok

# 啟動db服務

systemctl start postgresql-11

systemctl stop postgresql-11

# 設定開機啟動

systemctl enable postgresql-11

# 關閉防火牆

systemctl stop firewalld

systemctl disable firewalld

預設postgresql會建立乙個postgres使用者(linux)來訪問資料庫軟體。

注意:postgres不應該有其他的操作(例如連線到其他網路),這樣會給資料庫留下安全隱患。

# 修改postgres使用者密碼:

[root@node1 bin]# passwd postgres # [email protected]

# 切換到postgres使用者:

[root@node1 bin]# su - postgres

# 修改postgresql的postgres使用者的密碼:注意:linux上的postgres使用者用來訪問資料庫,postgresql 中的 postgres 使用者用來管理資料庫

bash-4.2$ psql -d template1 -c "alter user postgres with password '123456';" # 這裡我們測試用:123456

# 訪問資料庫:

bash-4.2$ psql postgres

psql (11.2)

type "help" for help.

postgres=#

# 配置檔案位置,如下是預設的配置檔案路徑:

vi /var/lib/pgsql/11/data/pg_hba.conf

# 在配置檔案的下面新增如下內容,允許所有位址進行訪問,通過md5加密的密碼,注意該檔案的優先順序是從上到下的,所以需要寫在預設的上面

host all all 0.0.0.0/0 md5

host all all 127.0.0.1/32 ident # 這裡是預設的位置

# 修改配置檔案

vi /var/lib/pgsql/11/data/postgresql.conf

listen_addresses = '*' # 監聽所有ip,預設是localhost

max_connections = 1000 # 預設100

tcp_keepalives_idle = 600 # tcp_keepidle, in seconds;

tcp_keepalives_interval = 10 # tcp_keepintvl, in seconds;

tcp_keepalives_count = 6 # tcp_keepcnt;

systemctl restart postgresql-11.service

postgresql安裝教程

pg相對於其他分布式的資料庫如greenplum,vertica的安裝已經是很簡單了。今天安裝postgresql了,那就順便把安裝過程記錄下吧 安裝環境說明 安裝版本 postgresql9.4 安裝系統環境 centos6.5 安裝 根據官網的介紹 1.首先更新yum源 yum install ...

離線安裝PostgreSQL

作業系統 centos5.8 x64 postgresql版本 9.1 伺服器未連線公網時怎麼安裝postgresql資料庫?伺服器版本為 centos5.8 x64 需要安裝的postgresql版本為 9.1 downloadonly引數需要安裝yum downloadonly,命令如下 yum...

postgresql 安裝指南

1.安裝postgresql 資料庫軟體包 apt get update apt get install y postgresql libpq dev 2.建立資料庫 sudo u postgres psql postgres create database netbox postgres crea...