SQL_Training_PostgreSQL

link





PostgreSQL Tutorial|🔝|


docker run

 docker run -p 5432:5432 --name test-postgres \
      -e POSTGRES_PASSWORD=1234 \
      -e TZ=Asia/Seoul \
      -d postgres:latest

Docker로 PostgreSQL 설치|🔝|

docker run --name {name-of-container} -v {name-of-volume}:{volume-storage-location} -p {desired-port}:5432 -e POSTGRES_PASSWORD={desired-password} -d {desired-postgres-image}

docker run -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=1q2w3e4r -d postgres


docker exec -it postgres /bin/bash




root@ac61c662ee4c:/# psql -U postgres
psql (13.0 (Debian 13.0-1.pgdg100+1))
Type "help" for help.

postgres=# CREATE USER seongwon PASSWORD '1q2w3e4r' SUPERUSER;
CREATE ROLE

postgres=# CREATE DATABASE test OWNER seongwon;
CREATE DATABASE

postgres=# \c test seongwon
You are now connected to database "test" as user "seongwon".
test=# CREATE TABLE star (
id integer NOT NULL,
name character varying(255),
class character varying(32),
age integer,
radius integer,
lum integer,
magnt integer,
CONSTRAINT star_pk PRIMARY KEY (id)
);
CREATE TABLE

test=# \dt
        List of relations
 Schema | Name | Type  |  Owner
--------+------+-------+----------
 public | star | table | seongwon
(1 row)

PostgreSQL에 sql파일 넣기|🔝|

psql -h localhost -d userstoreis -U admin -p 5432 -a -q -f /home/jobs/Desktop/resources/postgresql.sql

-h PostgreSQL server IP address
-d database name
-U user name
-p port which PostgreSQL server is listening on
-f path to SQL script
-a all echo
-q quiet 
-f file

export PGPASSWORD=<password>
psql -h <host> -d <database> -U <user_name> -p <port> -a -w -f <file>.sql

PostgreSQL 설치 위치(/bin/psql)|🔝|

psql --version
which psql

Mine is version 9.1.6 located in /bin/psql.

SQL명령어 그림으로 이해하기|🔝|


SQL Databases vs NoSQL Databases|🔝|

SQL Databases NoSQL Databases
1. PostgreSQL
2. MySQL
3. SQLite
4. SQL Server
5. Oracle
6. CockroachDB
1. Mongo DB
2. Redis
3. ElasticSearch
4. Firebase
5. Dynamo DB

PostgreSQL|🔝|


(230824)SQL For Web Developers - Complete Database Course | freeCodeCamp.org|🔝|


SQL for Data Analytics - Learn SQL in 4 Hours | Luke Barousse|🔝|


(241009)Databases In-Depth – Complete Course | freeCodeCamp.org|🔝|

macOS(Path)|🔝|

If you need to have libpq first in your PATH, run:
  fish_add_path /opt/homebrew/opt/libpq/bin

For compilers to find libpq you may need to set:
  set -gx LDFLAGS "-L/opt/homebrew/opt/libpq/lib"
  set -gx CPPFLAGS "-I/opt/homebrew/opt/libpq/include"

For pkg-config to find libpq you may need to set:
  set -gx PKG_CONFIG_PATH "/opt/homebrew/opt/libpq/lib/pkgconfig"