Run the following command to create a database named mydb
The code is as follows: |
|
Createdb mydb |
The following error is returned: psql: FATAL: role "terry" does not exist. terry is the name of my machine and there is no role named terry in the postgresql database. Therefore, this error is reported, you only need to add the-U parameter to specify an existing role, so I changed the above command:
The code is as follows: |
|
Createdb mydb-U postgres |
Another error is returned: psql: FATAL: Peer authentication failed for user "s ",
The solution is as follows:
1. Run the following command to edit the pg_cmd.conf file.
The code is as follows: |
|
Sudo gedit/etc/postgresql/9.1/main/pg_assist.conf |
2. Set
The code is as follows: |
|
# Database administrative login by Unix domain socket Local all IPVs peer Change # Database administrative login by Unix domain socket Local all IPVs trust |
3. Save and execute the following command to reload the configuration file:
The code is as follows: |
|
Sudo/etc/init. d/postgresql reload |
Then run createdb mydb1-U postgres to create the mydb1 database.
You have not translated a foreign document. For more information, see.
I figured I 'd share getting setup on my Ubuntu machine.
Installing
Sudo apt-get install postgresql
Creating User
Createdb book
Createuser: cocould 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 shoshould work
Createdb book
Installing Extensions
There shoshould be more problems when trying to create the 5 extensions
Psql book-c "create extension tablefunc"
ERROR: cocould 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 shoshould be good to go!
Thanks to the post by Tanner Watson for the create extension command