POSTGRESQL 無法建立資料庫 出現類似createdb: could not connect

來源:互聯網
上載者:User

運行下面的命令建立名為mydb的資料庫

 代碼如下 複製代碼

createdb mydb

得到一個錯誤:psql: FATAL: role "terry" does not exist, terry是我的機器名, 在postgresql資料庫中沒有名為terry的role, 所以會報出這個錯誤, 只要加上-U參數來指定一個存在的role就可以了,所以我將上面的命令改為:

 代碼如下 複製代碼

createdb mydb -U postgres

又得到一個錯誤:psql: FATAL:  Peer authentication failed for user "postgres",

解決辦法如下:

1. 運行下面的命令編輯pg_hba.conf檔案

 代碼如下 複製代碼

sudo gedit /etc/postgresql/9.1/main/pg_hba.conf

2. 將

 代碼如下 複製代碼

# Database administrative login by Unix domain socket
local   all             postgres                                peer

改為

# Database administrative login by Unix domain socket
local   all             postgres                                trust

3. 儲存後執行下面的命令重新載入設定檔:

 代碼如下 複製代碼

sudo /etc/init.d/postgresql reload

再執行 createdb mydb1 -U postgres , 已經成功的建立了mydb1資料庫.


看一老外的檔案沒譯,各位有需要可參考。

I figured I’d share getting setup on my Ubuntu machine.

Installing

sudo apt-get install postgresql
Creating User

createdb book
createuser: could not connect to database postgres: FATAL:  role "myusername" does not exist


The bit above can be resolved with the following (replacing myusername for yours)

sudo -u postgres createuser myusername
Shall the new role be a superuser? (y/n) y


Then this should work

createdb book


Installing Extensions
There should be more problems when trying to create the 5 extensions

psql book -c "CREATE EXTENSION tablefunc"
ERROR:  could not open extension control file "/usr/share/postgresql/9.1/extension/tablefunc.control": No such file or directory


You can fix it by just downloading a package.

sudo apt-get install postgresql-contrib


Downloading the postgresql-contrib packages will give the ability to use the following five commands:

psql book -c "CREATE EXTENSION tablefunc"
psql book -c "CREATE EXTENSION fuzzystrmatch"
psql book -c "CREATE EXTENSION pg_trgm"
psql book -c "CREATE EXTENSION cube"
psql book -c "CREATE EXTENSION dict_xsyn"


And now you should be good to go!

Thanks to the post by Tanner Watson for the CREATE EXTENSION command

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.