運行下面的命令建立名為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