CS/데이터베이스
docker에서 postgresql table 확인
Junuuu
2023. 6. 27. 00:01
728x90
docker-compose.yaml
version: '3.8'
services:
postgresql:
image: postgres:14.6
# volumes:
# - ~/volumes/jhipster/jhip_api_first/postgresql/:/var/lib/postgresql/data/
environment:
- POSTGRES_DB=postgresdb
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=psltest
- POSTGRES_HOST_AUTH_METHOD=trust
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:5432:5432
command: [ "postgres", "-c", "max_connections=1000", "-c", "max_prepared_transactions=100" ]
docker ps로 컨테이너명 확인
docker ps
컨테이너명으로 bash 실행
docker exec -it your-container-name /bin/bash
postgresql 접속
psql --username admin --dbname postgresdb
database 연결
\c postgresdb
스키마 조회
SELECT schema_name FROM information_schema.schemata;
users 테이블 생성
CREATE TABLE users (
name VARCHAR(50)
);
table 확인방법
\dt+
data insert
INSERT INTO users (name) VALUES ('John');
INSERT INTO users (name) VALUES ('Jane');
select로 확인
SELECT * FROM users;