-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (full-stack): PostgreSQL setup and example
- Loading branch information
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# PostgreSQL on Ubuntu | ||
|
||
These are Ubuntu instructions. They may vary on Windows and Mac. | ||
|
||
## Install Ubuntu | ||
|
||
Installation instructions: | ||
https://www.postgresql.org/download/linux/ubuntu/ | ||
|
||
The simplest approach probably will not install the latest version: | ||
~~~ | ||
apt install postgresql | ||
~~~ | ||
|
||
To install the latest one, follow the instructions of "manually configure the Apt repository". | ||
|
||
## Changing the Password | ||
|
||
~~~ | ||
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" | ||
~~~ | ||
|
||
## Server Management | ||
|
||
The three following commands start, stop, and show the status of the server at Ubuntu, respectively: | ||
|
||
~~~ | ||
sudo systemctl start postgresql | ||
sudo systemctl stop postgresql | ||
sudo systemctl status postgresql | ||
~~~ | ||
|
||
Reference: https://tableplus.com/blog/2018/10/how-to-start-stop-restart-postgresql-server.html | ||
|
||
## Repository Location | ||
|
||
To change the database location at Ubuntu: | ||
https://www.digitalocean.com/community/tutorials/how-to-move-a-postgresql-data-directory-to-a-new-location-on-ubuntu-20-04 | ||
|
||
|
||
# PostgreSQL Docker | ||
|
||
Image: https://hub.docker.com/_/postgres | ||
|
||
The `docker-compose.yml` has the instruction for docker compose. To run: | ||
~~~ | ||
docker compose up | ||
~~~ |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: '3' | ||
|
||
services: | ||
db: | ||
image: postgres | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
restart: on-failure:5 | ||
shm_size: 128mb | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
ports: | ||
- "5431:5432" | ||
|
||
volumes: | ||
postgres-data: | ||
driver: "local" | ||
driver_opts: | ||
type: "none" | ||
device: "/home/santanche/data/pgsql/docker" | ||
o: "bind" |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE users ( | ||
email_id VARCHAR(320), | ||
name VARCHAR(100) NOT NULL, | ||
birthday DATE, | ||
PRIMARY KEY (email_id) | ||
); | ||
|
||
INSERT INTO users VALUES ('asdrubal@email.com', 'Asdrubal', '2024-01-20'); | ||
INSERT INTO users VALUES ('doriana@email.com', 'Doriana', '2024-03-05'); | ||
INSERT INTO users VALUES ('bonerges@email.com', 'Bonerges', '2024-05-01'); |