linux下postgres的安裝

軟件包的下載

在瀏覽器中訪問https://www.enterprisedb.com/download-postgresql-binaries 而後選擇適合本身的版本,我選擇的是linux64位下的10.0.7版本,下載後獲得一下的包:postgresql-10.7-1-linux-x64-binaries.tar.gzlinux

安裝並初始化

解壓並安裝到制定的目錄sql

tar -zxvf postgresql-10.7-1-linux-x64-binaries.tar.gz -C /opt/postgres

如今postgres的安裝目錄就是/opt/postgres/pgsql數據庫

建立postgres用戶並設置密碼瀏覽器

useradd postgres
passwd postgres

注意:這裏設置密碼是linux用戶postgres的登陸密碼,不是pgsql服務器的密碼bash

建立postgres的數據存放目錄,給postgres用戶受權目錄訪問權限服務器

mkdir /opt/postgres/pg_data
chown postgres /opt/postgres/pg_data

而後切換到postgres用戶來操做數據庫,pgsql數據庫就以postgres爲默認用戶,執行: su - postgres 切換post

切換以後建議修改~/.bash_profile將pgsql的bin目錄加至環境變量中,方便直接使用pgsql相關命令,下面初始化數據庫:日誌

/opt/postgres/pgsql/bin/initDb -D /opt/postgres/pg_data

等待執行完畢,沒什麼問題就初始化成功了.postgresql

啓動數據庫code

/opt/postgres/pgsql/bin/pg_ctl  -D  /opt/postgres/pg_data/ -l logfile start

這裏-l指定日誌文件位置,這裏直接輸出在家目錄下的logfile中,這個能夠本身指定,這裏-D指定數據目錄,默認若是不加數據目錄直接報錯找不到,能夠剛纔說的環境變量配置文件中~/.bash_profile加入一行: export PGDATA=/monchickey/pgsql_data 而後source進去便可,這樣pgsql會自動去找PGDATA環境變量值,找不到纔會報錯

pgsql默認的端口號爲5432,經過netstat命令或者lsof命令均可以看到監聽狀況

如今能夠看到pgsql默認監聽的是localhost或127.0.0.1,目前只能本機訪問,若是遠程訪問就鏈接不上了,具體的配置文件是data目錄下的postgresql.conf,能夠經過修改這個配置文件來調整各個參數,好比:listen_addresses能夠修改綁定的地址,默認是localhost,port能夠修改監聽的端口號,默認是5432,max_connections能夠修改最大客戶端鏈接數量,默認是100等等,這裏就再也不詳細說了

中止postgresql的命令爲

/opt/postgres/pgsql/bin/pg_ctl  -D  /opt/postgres/pg_data/  stop

這樣postgres就安裝完成了

相關文章
相關標籤/搜索