本篇內(nèi)容介紹了“postgresql數(shù)據(jù)庫的安裝以及修改數(shù)據(jù)文件路徑的方法”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站是一家企業(yè)級云計算解決方案提供商,超15年IDC數(shù)據(jù)中心運營經(jīng)驗。主營GPU顯卡服務器,站群服務器,服務器托管機柜,海外高防服務器,成都機柜租用,動態(tài)撥號VPS,海外云手機,海外云服務器,海外服務器租用托管等。一:postgresql數(shù)據(jù)庫的安裝:兩種方法1,安裝包安裝。2,yum安裝
1.yum安裝。
結(jié)合自己的操作系統(tǒng)下載postgresql鏡像。之后會顯示如何使用yum安裝和啟動postgresql,如下圖:
Install the repository RPM:
yum installhttps://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-1.noarch.rpm
Install the client packages:
yum install postgresql10
Optionally install the server packages:
yum install postgresql10-server
Optionally initialize the database and enable automatic start:
service postgresql-10 initdb
chkconfig postgresql-10 on
service postgresql-10 start
2).使用鏡像安裝。
1、下載postgresql最新版:http://www.postgresql.org/ftp/source/
或者在官網(wǎng)中選擇對應的os系統(tǒng)和你想要的postgresql版本,然后點擊下載企業(yè)版:
https://www.enterprisedb.com/download-postgresql-binaries
之后選擇需要的版本
2、解壓文件:
tar zxvf postgresql-8.3.7.tar.gz
cd postgresql-8.3.7
3、編譯,指定安裝postgresql的路徑
./configure --prefix=/usr/local/pgsql
4、編譯:
make
5、安裝:
make install
6、創(chuàng)建用戶組和用戶:
groupadd postgres
useradd -g postgres postgres
7、創(chuàng)建數(shù)據(jù)庫庫文件存儲目錄、給postgres賦予權(quán)限:
mkdir /usr/local/pgsql/data
cd /usr/local/pgsql
chown postgres.postgres data
8、編輯~/.bash_profile文件
#vi ~/.bash_profile
設置以下的環(huán)境變量
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
9、初始化數(shù)據(jù)庫目錄:
切換用戶
su - postgresql
初始化數(shù)據(jù) -D指定初始化創(chuàng)建的數(shù)據(jù)庫的文件路徑
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
二:啟動,登錄,退出
如果需要指定環(huán)境變量,請按如下方式:
postgres@lgr-pc:~$ vi .bash_profile
添加如下內(nèi)容:
export PGDATA=/usr/local/pgsql/data;
export PATH=$PATH:$HOME/bin:/usr/local/pgsql/bin
即指定pgdata和bin的目錄,這里可以根據(jù)自己的實際目錄指定。
編輯完環(huán)境變量文件后,運行如下命令使環(huán)境變量生效:
postgres@lgr-pc:~$ . .bash_profile
設置完環(huán)境變量,運行如下命令啟動服務器:
postgres@lgr-pc:~$ pg_ctl start
二 登錄服務器
當安裝完數(shù)據(jù)庫后,我們會有一個系統(tǒng)用戶,一個數(shù)據(jù)庫,一個數(shù)據(jù)庫用戶,他們默認的名稱為:postgres
1. 如果沒有設置bin目錄的環(huán)境變量,那么
postgres@lgr-pc:~$ /usr/local/pgsql/bin/psql
這樣默認登錄到postgres庫中,當然也可以在psql后面加上庫的名稱,這樣就可以登錄到指定庫中。如登錄到test庫:
postgres@lgr-pc:~$ /usr/local/pgsql/bin/psql test
如果您也像我一樣設置了bin目錄的環(huán)境變量,那么
postgres@lgr-pc:~$ psql
這樣默認的也是登錄到postgres庫中,同樣的我們可以指定數(shù)據(jù)庫名稱,登錄到指定庫。
postgres@lgr-pc:~$ psql test
三 退出登錄
退出登錄就很簡單了,我們可以運行\(zhòng)q,或者ctrl+d
postgres=# \q
四 關閉數(shù)據(jù)庫服務器
關閉:
postgres@lgr-pc:~$ pg_ctl stop
重啟:
postgres@lgr-pc:~$ pg_ctl restart
三:PGSQL更改數(shù)據(jù)的存儲路徑:
1)在數(shù)據(jù)庫軟件安裝之后,初始化數(shù)據(jù)庫時候,可以指定初始化時創(chuàng)建的數(shù)據(jù)庫的默認文件路徑,
指定數(shù)據(jù)庫存放位置和編碼方式,初始化數(shù)據(jù)庫:
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
這樣初始化之后,再修改配置文件postgresql.conf為修改之后的數(shù)據(jù)文件路徑,就能保證以后的數(shù)據(jù)文件也在這個路徑下了。
2)如果是已經(jīng)初始化好了,再修改數(shù)據(jù)文件路徑的,如下過程:
找到配置文件查看原來的數(shù)據(jù)存儲路徑在哪
sudo find / -name postgresql.conf
一般是在/etc/postgresql/9.6/main/postgresql.conf
停掉PGSQL
sudo service postgresql stop
拷貝原來的數(shù)據(jù)路徑到新的路徑下
sudo cp -rf /var/lib/postgresql/9.6/main/ /data/postgresql/
設置用戶和權(quán)限
sudo chown -R postgres:postgres /data/postgresql/
sudo chmod 700 /data/postgresql/
將配置文件的數(shù)據(jù)存儲路徑改成新的
sudo vim /etc/postgresql/9.6/main/postgresql.conf
data_directory=‘/data/postgresql/datafile’
再啟動就行了
sudo service postgresql start
快速找到 配置文件中 data_directory所在的行數(shù):
bogon:root@/usr/pgsql-10/bin>cat /var/lib/pgsql/10/data/postgresql.conf | grep -n data_directory
41:#data_directory = 'ConfigDir' # use data in another directory
修改完畢后,可以用psql命令“show data_directory”查看當前數(shù)據(jù)目錄
postgres=# show data_directory;
data_directory
------------------------
/var/lib/pgsql/10/data
(1 row)
“postgresql數(shù)據(jù)庫的安裝以及修改數(shù)據(jù)文件路徑的方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)-成都網(wǎng)站建設公司網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
網(wǎng)頁標題:postgresql數(shù)據(jù)庫的安裝以及修改數(shù)據(jù)文件路徑的方法-創(chuàng)新互聯(lián)
路徑分享:http://muchs.cn/article24/dpihce.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、電子商務、網(wǎng)站維護、移動網(wǎng)站建設、App設計、虛擬主機
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容