Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
postgresql_createadatabase [2018/11/22 13:31] – created andonovj | postgresql_createadatabase [2019/10/18 20:04] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
- | ===Create user=== | + | ====Create user==== |
+ | ---- | ||
In PostgreSQL, there are 2 kind of roles: | In PostgreSQL, there are 2 kind of roles: | ||
- Role which can connect - Called Users | - Role which can connect - Called Users | ||
Line 20: | Line 21: | ||
This command will create a role, which can login, thus User :) | This command will create a role, which can login, thus User :) | ||
- | ===Create database with owner=== | + | ====Create database with owner==== |
+ | ---- | ||
Now we can create a database using this user: | Now we can create a database using this user: | ||
<sxh bash> | <sxh bash> | ||
Line 31: | Line 33: | ||
- | ===Grant privileges=== | + | ====Grant privileges==== |
+ | ---- | ||
Just because a user is owner of a database, this doesn' | Just because a user is owner of a database, this doesn' | ||
Line 45: | Line 48: | ||
P.S. Do not forget to update the pg_hba.conf and reload the profile so the user(ROLE) can connect to it :) | P.S. Do not forget to update the pg_hba.conf and reload the profile so the user(ROLE) can connect to it :) | ||
+ | ====Get the size of all databases==== | ||
+ | ---- | ||
+ | Easy way to get the size of databases is to execute the following query: | ||
+ | |||
+ | <sxh bash> | ||
+ | postgres=# | ||
+ | SELECT database_name, | ||
+ | from | ||
+ | (SELECT pg_database.datname as " | ||
+ | FROM pg_database ORDER by size DESC) as ordered; | ||
+ | | ||
+ | | ||
+ | | ||
+ | ---------------------------+---------------- | ||
+ | | ||
+ | | ||
+ | | ||
+ | (3 rows) | ||
+ | </ |