Skip to content

Commit

Permalink
feat (full-stack): PostgreSQL setup and example
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Aug 11, 2024
1 parent f8786b5 commit 0e19012
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
48 changes: 48 additions & 0 deletions full-stack/postgresql/README.md
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
~~~
21 changes: 21 additions & 0 deletions full-stack/postgresql/docker-compose.yml
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"
10 changes: 10 additions & 0 deletions full-stack/postgresql/schema.sql
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');

0 comments on commit 0e19012

Please sign in to comment.