-
-
Save Taher1307/7fc83709fe038d020952f07b19f421be to your computer and use it in GitHub Desktop.
Revisions
-
phortuin revised this gist
Oct 5, 2021 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,7 +70,13 @@ postgres-> \c mydatabase mydatabase-> \dt ``` ...should print `Did not find any relations.` for an empty database. To quit the postgres CLI: ``` mydatabase-> \q ``` Finally, in a `.env` file for Node.js software development, your database connection string should look like this: ``` PG_CONNECTION_STRING=postgres://myuser@localhost/mydatabase -
phortuin revised this gist
Sep 21, 2021 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,8 +23,8 @@ $ psql postgres Create role for application, give login and `CREATEDB` permissions: ```postgres postgres-# CREATE ROLE myuser WITH LOGIN; postgres-# ALTER ROLE myuser CREATEDB; ``` Note that the user has no password. Listing users `\du` should look like this: @@ -35,7 +35,7 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- <root user> | Superuser, Create role, Create DB, Replication, Bypass RLS | {} myuser | Create DB | {} ``` Quit psql, because we will login with the new role (=user) to create a database: @@ -44,17 +44,17 @@ Quit psql, because we will login with the new role (=user) to create a database: postgres-# \q ``` On shell, open psql with `postgres` database with user `myuser`: ```bash $ psql postgres -U myuser ``` Note that the postgres prompt looks different, because we’re not logged in as a root user anymore. We’ll create a database and grant all privileges to our user: ```postgres postgres-> CREATE DATABASE mydatabase; postgres-> GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myuser; ``` List databases to verify: @@ -66,12 +66,12 @@ postgres-> \list If you want to connect to a database and list all tables: ```postgres postgres-> \c mydatabase mydatabase-> \dt ``` ...should print `Did not find any relations.` for an empty database. Finally, in a `.env` file for Node.js software development, your database connection string should look like this: ``` PG_CONNECTION_STRING=postgres://myuser@localhost/mydatabase ``` -
phortuin revised this gist
Sep 20, 2021 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,9 +70,7 @@ postgres-> \c myapp myapp-> \dt ``` ...should print `Did not find any relations.` for an empty database. Finally, in a `.env` file for Node.js software development, your database connection string should look like this: ``` PG_CONNECTION_STRING=postgres://myapp@localhost/myapp -
phortuin revised this gist
Sep 20, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ myapp-> \dt ...should print `Did not find any relations.` for an empty database. In a `.env` file for Node.js software development, your database connection string should look like this. ``` PG_CONNECTION_STRING=postgres://myapp@localhost/myapp -
phortuin revised this gist
Sep 20, 2021 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -70,4 +70,10 @@ postgres-> \c myapp myapp-> \dt ``` ...should print `Did not find any relations.` for an empty database. Your connection string should look like this: ``` PG_CONNECTION_STRING=postgres://myapp@localhost/myapp ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ $ brew install postgresql Run server: ```bash $ pg_ctl -D /opt/homebrew/var/postgres start ``` Note: if you’re on Intel, the `/opt/homebrew` probably is `/usr/local`. -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -48,4 +48,26 @@ On shell, open psql with `postgres` database with user `myapp`: ```bash $ psql postgres -U myapp ``` Note that the postgres prompt looks different, because we’re not logged in as a root user anymore. We’ll create a database and grant all privileges to our user: ```postgres postgres-> CREATE DATABASE myapp; postgres-> GRANT ALL PRIVILEGES ON DATABASE myapp TO myapp; ``` List databases to verify: ```postgres postgres-> \list ``` If you want to connect to a database and list all tables: ```postgres postgres-> \c myapp myapp-> \dt ``` ...should print `Did not find any relations.` for an empty database. -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,7 +14,7 @@ $ pg_ctl -D /opt/homebrew/var/postgres start Note: if you’re on Intel, the `/opt/homebrew` probably is `/usr/local`. Start psql and open database `postgres`, which is the database postgres uses itself to store roles, permissions, and structure: ```bash $ psql postgres @@ -35,5 +35,17 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- <root user> | Superuser, Create role, Create DB, Replication, Bypass RLS | {} myapp | Create DB | {} ``` Quit psql, because we will login with the new role (=user) to create a database: ```postgres postgres-# \q ``` On shell, open psql with `postgres` database with user `myapp`: ```bash $ psql postgres -U myapp ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,8 @@ Run server: $ pg_ctl -D /opt/homebrew/var/postgres start ``` Note: if you’re on Intel, the `/opt/homebrew` probably is `/usr/local`. Start psql and open database `postgres`: ```bash -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,7 +22,7 @@ Create role for application, give login and `CREATEDB` permissions: ```postgres postgres-# CREATE ROLE myapp WITH LOGIN; postgres-# ALTER ROLE myapp CREATEDB; ``` Note that the user has no password. Listing users `\du` should look like this: @@ -33,5 +33,5 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- <root user> | Superuser, Create role, Create DB, Replication, Bypass RLS | {} myapp. | Create DB | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,6 +32,6 @@ postgres-# \du List of roles Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- <root user> | Superuser, Create role, Create DB, Replication, Bypass RLS | {} traxcal | Create DB | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,5 +33,5 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- (root user) | Superuser, Create role, Create DB, Replication, Bypass RLS | {} traxcal | Create DB | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,11 @@ $ psql postgres Create role for application, give login and `CREATEDB` permissions: ```postgres postgres-# CREATE ROLE myapp WITH LOGIN; postgres-# ALTER ROLE traxcal CREATEDB; ``` Note that the user has no password. Listing users `\du` should look like this: ```postgres postgres-# \du -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,10 +18,10 @@ Start psql and open database `postgres`: $ psql postgres ``` Create role for application, give login and `CREATEDB` permissions: ```postgres postgres-# CREATE ROLE myapp WITH LOGIN PASSWORD '<password>'; postgres-# ALTER ROLE traxcal CREATEDB; ``` @@ -33,5 +33,5 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- (root user) | Superuser, Create role, Create DB, Replication, Bypass RLS | {} myapp | Create DB. | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,5 +33,5 @@ postgres-# \du Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- (root user) | Superuser, Create role, Create DB, Replication, Bypass RLS | {} myapp | Create DB, Cannot login | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,16 @@ Create role for application and give rights (the semicolon at the end is importa ```postgres postgres-# CREATE ROLE myapp; postgres-# ALTER ROLE traxcal CREATEDB; ``` User should look like this: ```postgres postgres-# \du List of roles Role name | Attributes | Member of -------------+------------------------------------------------------------+----------- (root user) | Superuser, Create role, Create DB, Replication, Bypass RLS | {} traxcal | Create DB, Cannot login | {} ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,15 +12,16 @@ Run server: $ pg_ctl -D /opt/homebrew/var/postgres start ``` Start psql and open database `postgres`: ```bash $ psql postgres ``` Create role for application and give rights (the semicolon at the end is important): ```postgres postgres-# CREATE ROLE myapp; # CREATE ROLE postgres-# ALTER ROLE traxcal CREATEDB ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,8 +18,9 @@ Start psql with default user `postgres`: $ psql postgres ``` Create role for application and give rights: ```postgres posgres-# CREATE ROLE myapp postgres-# ALTER ROLE traxcal CREATEDB ``` -
phortuin revised this gist
Jul 4, 2021 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,3 +17,9 @@ Start psql with default user `postgres`: ```bash $ psql postgres ``` Create role for application: ```postgres posgres-# CREATE ROLE myapp ``` -
phortuin created this gist
Jul 4, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ Based on [this blogpost](https://www.codementor.io/@engineerapart/getting-started-with-postgresql-on-mac-osx-are8jcopb). Install with Homebrew: ```bash $ brew install postgresql ``` Run server: ```bash $ pg_ctl -D /opt/homebrew/var/postgres start ``` Start psql with default user `postgres`: ```bash $ psql postgres ```