diff --git a/full-stack/postgresql/README.md b/full-stack/postgresql/README.md new file mode 100644 index 0000000..f341e14 --- /dev/null +++ b/full-stack/postgresql/README.md @@ -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 +~~~ \ No newline at end of file diff --git a/full-stack/postgresql/docker-compose.yml b/full-stack/postgresql/docker-compose.yml new file mode 100644 index 0000000..98a727a --- /dev/null +++ b/full-stack/postgresql/docker-compose.yml @@ -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" diff --git a/full-stack/postgresql/schema.sql b/full-stack/postgresql/schema.sql new file mode 100644 index 0000000..58c1c71 --- /dev/null +++ b/full-stack/postgresql/schema.sql @@ -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'); \ No newline at end of file