리눅스 접속
- su - postgres
Postgresql 터미널 접속
- psql -U postgres
/* 사용자 계정 생성 */
create user test password 'test2021' superuser;
/* 데이터 베이스 생성 */
create database test_db owner test;
/* 테이블 스페이스 저정될 폴더를 먼저 생성한다.*/
mkdir -p /postgre_db/test_dat
mkdir -p /postgre_db/test_idx
chown -R postgrs:postgres /postgre_db
/* 테이블 스페이스 생성 */
CREATE TABLESPACE test_tbl owner test LOCATION '/postgre_db/test_dat';
CREATE TABLESPACE test_idx owner test LOCATION '/postgre_db/test_idx';
/* 스키마 생성 */
\c test_db test
CREATE SCHEMA IF NOT EXISTS test AUTHORIZATION test;
/* 스키마 삭제 */
DROP SCHEMA test cascade;
/* 스키마 생성 확인 */
\dn
/* 윈도우 db 정보 dump */
/* db 전체 백업(윈도우) */
pg_dump.exe --file "C:\\postgre_dump\\test_full.dump" --host "localhost" --port "5432" --username "postgres" --password --verbose --format=c --section=pre-data --section=data --section=post-data --column-inserts --encoding "UTF8" "test_db"
/* db해당 스키마 백업(윈도우) */
pg_dump.exe --file "C:\\postgre_dump\\test.dump" --host "localhost" --port "5432" --username "postgres" --password --verbose --format=c --section=pre-data --section=data --section=post-data --column-inserts --encoding "UTF8" --schema "test" "test_db"
/* db전체복원(리눅스) */
/* db전체 복원하기 위해서는 사용자 계정과 테이블스페이스를 먼저 생성해 줘야 한다. */
pg_restore --host "192.168.1.42" --port "5432" --username "postgres" --password --dbname "test_db" --section=pre-data --section=data --section=post-data --verbose "/postgre_db/dump/test_full.dump"
/* 스키마 단위로 복원(리눅스) */
/* 스키마 단위로 복원은 사용자계정,테이블스페이스,스키마까지 생성하고 복원해야 한다. */
/* test */
pg_restore --host "192.168.1.42" --port "5432" --username "postgres" --password --dbname "test_db" --section=pre-data --section=data --section=post-data --verbose --schema "test" "/postgre_db/dump/test.dump"
/* 스키마 단위 풀 복원(리눅스) 스키마 자동생성된다 */
pg_restore --host "192.168.1.42" --port "5432" --username "postgres" --password --dbname "test_db" --section=pre-data --section=data --section=post-data --verbose "/postgre_db/dump/test.dump"
/* 사용자 생성후 사용자로 로그인시 아래와 같은 오류 밣생시 */
[postgres@namenode ~]$ psql -U test
psql: 오류: 치명적오류: 사용자 "test"의 peer 인증을 실패했습니다.
[postgres@namenode ~]$ cat /var/lib/pgsql/13/data/pg_hba.conf
pg_hba.conf 파일을 열어서
로컬일 경우
local all all peer
peer을 md5로 변경하고 재시작 하여야 한다.
생성된 데이터 베이스 조회
\l
postgres=# \l
데이터베이스 목록
이름 | 소유주 | 인코딩 | Collate | Ctype | 액세스 권한
-----------+----------+--------+-------------+-------------+-----------------------
test | naqsifh | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 |
postgres | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 |
template0 | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | ko_KR.UTF-8 | ko_KR.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4개 행)
생성된 데이터 베이스 접속
\c db명 사용자
\c test_db test
postgres=# \c test_db test
test 사용자의 암호:
접속정보: 데이터베이스="test_db", 사용자="test".
test_db=#
/* 생성된 사용자 조회 */
select * from pg_shadow;
'데이터베이스 > Postgresql' 카테고리의 다른 글
[PostgreSql] 패스워드 없이 백업 및 복원 (0) | 2021.11.09 |
---|---|
[PostgreSql] postgresql 13 확장팩 설치 (0) | 2021.11.08 |
[PostgreSQL] 날짜 범위 검색 (0) | 2021.10.01 |
[PostgreSQL] lock 확인,삭제 (0) | 2021.09.29 |
테이블의 스키마와 owner 변경하기 (0) | 2021.09.29 |
댓글