레이블이 postgres인 게시물을 표시합니다. 모든 게시물 표시
레이블이 postgres인 게시물을 표시합니다. 모든 게시물 표시

2022년 10월 24일 월요일

postgresql 데이터 백업/관리

  1. DB데이터 백업하기
    -bash-4.1$ pg_dump testdb >  test.sql

  2. DB 스키마만 덤프할때
    bash-4.1$ pg_dump -s testdb >  test.sql

  3. 데이터 복원
    bash-4.1$ psql  testdb < test.sql

2022년 10월 21일 금요일

postgres 로그디렉토리 생성하기

 mkdir -p /var/log/pgsql/

chown -R postgres.dba /var/log/pgsql/



vi /usr/local/pgsql/data/postgresql.conf

logging_collector = on

log_destination = 'stderr' 

redirect_stderr = true 

log_directory = '/var/log/pgsql/' 


log_filename = 'pgsql-%Y-%m-%d_%H%M%S.log' 

log_rotation_size = 500MB



출처 - http://igoni.kr/books/dbms/page/postgres

postgres 기초쿼리 정보들

 

  1. 테이블 리스트
    \dt;

  2. 테이블 정보 보기
    \d 테이블 이름

  3. 테이블 데이터형 변경
    postgres=# alter table cities alter column location type varchar(20);

  4. 테이블 스페이스 생성
    postgres=#  create tablespace testdb_space owner testuser location '/usr/local/pgsql/data/testdb';

    해당 경로는 미리 생성이 되어 있어야 하고, postgres, dba의 권한으로 설정이 되어 있어야 한다.


  5. DB생성
    postgres=# create database testdb owner testuser tablespace testdb;

  6. 테이블 생성
    testdb=> create table member ( num int, name varchar(100) );

  7. 데이터 삽입
    testdb=> insert into member values (1,'test');

출처

postgresql 트랜젝션 테스트

 testdb=> select * from member;

 num |   name
-----+-----------
   1 | test
   2 | test123
   3 | test12
   4 | test12
   5 | test12
   6 | test12123
(6 rows)

testdb=> begin;
BEGIN
testdb=> insert into member values (7,'test12123');
INSERT 0 1
testdb=> insert into member values (8,'test12123');
INSERT 0 1
testdb=> select * from member;
 num |   name
-----+-----------
   1 | test
   2 | test123
   3 | test12
   4 | test12
   5 | test12
   6 | test12123
   7 | test12123
   8 | test12123
(8 rows)

testdb=> rollback;
ROLLBACK
testdb=> select * from member;
 num |   name
-----+-----------
   1 | test
   2 | test123
   3 | test12
   4 | test12
   5 | test12
   6 | test12123
(6 rows)

2022년 8월 4일 목요일

postgresSQL 9.4.26 설치

패키지 설치진행

  1. db실행 사용자 및 data 디렉토리 생성
    $> useradd psql
    $> mkdir /home/data
    $> chown -R psql: /home/data
  2. source 파일 다운로드
    $> wget https://ftp.postgresql.org/pub/source/v9.4.26/postgresql-9.4.26.tar.gz --no-check-certificate
  3. depencency 패키지 설치
    $> yum install \
    readline-devel \
    zlib-devel \
    openssl-devel \
    tcl-devel -y
  4. 컴파일 후 설치진행
    $> ./configure --prefix=/usr/local/psql --with-openssl --with-tcl
    $> make -j 4
    $> make -j 4 install

DB 실행

  1. psql 실행
    $> su - psql
    $> cd /usr/local/psql/bin
    $> ./initdb -D /home/data
    
    The files belonging to this database system will be owned by user "psql".
    This user must also own the server process.
    
    The database cluster will be initialized with locale "ko_KR.UTF-8".
    The default database encoding has accordingly been set to "UTF8".
    initdb: could not find suitable text search configuration for locale "ko_KR.UTF-8"
    The default text search configuration will be set to "simple".
    
    Data page checksums are disabled.
    
    fixing permissions on existing directory /home/data ... ok
    creating subdirectories ... ok
    selecting default max_connections ... 100
    selecting default shared_buffers ... 128MB
    selecting default timezone ... ROK
    selecting dynamic shared memory implementation ... posix
    creating configuration files ... ok
    creating template1 database in /home/data/base/1 ... ok
    initializing pg_authid ... ok
    initializing dependencies ... ok
    creating system views ... ok
    loading system objects' descriptions ... ok
    creating collations ... ok
    creating conversions ... ok
    creating dictionaries ... ok
    setting privileges on built-in objects ... ok
    creating information schema ... ok
    loading PL/pgSQL server-side language ... ok
    vacuuming database template1 ... ok
    copying template1 to template0 ... ok
    copying template1 to postgres ... ok
    syncing data to disk ... ok
    
    WARNING: enabling "trust" authentication for local connections
    You can change this by editing pg_hba.conf or using the option -A, or
    --auth-local and --auth-host, the next time you run initdb.
    
    Success. You can now start the database server using:
    
        ./postgres -D /home/data
    or
        ./pg_ctl -D /home/data -l logfile start
  2. 프로세스 실행
    $ /usr/local/psql/bin/postgres -D /home/data/ >logfile  2>&1 &
  3. 프로세스 실행상태 확인
    $> ps -ef | grep post
    psql     16193 16108  0 10:54 pts/0    00:00:00 /usr/local/psql/bin/postgres -D /home/data/
    psql     16195 16193  0 10:54 ?        00:00:00 postgres: checkpointer process
    psql     16196 16193  0 10:54 ?        00:00:00 postgres: writer process
    psql     16197 16193  0 10:54 ?        00:00:00 postgres: wal writer process
    psql     16198 16193  0 10:54 ?        00:00:00 postgres: autovacuum launcher process
    psql     16199 16193  0 10:54 ?        00:00:00 postgres: stats collector process
    psql     16201 16108  0 10:54 pts/0    00:00:00 grep --color=auto post
    
     netstat -antp | grep postgres
    (Not all processes could be identified, non-owned process info
     will not be shown, you would have to be root to see it all.)
    tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      16193/postgres
    tcp6       0      0 ::1:5432                :::*                    LISTEN      16193/postgres


postgresSQL 9.2.4 설치

  1. 설치정보
    • Postgressql : 9.2.4
    • OS : Centos 5.10
  2. postgressql 컴파일때 필요한 패키지 설치
    $> yum -y install compat-readline43 readline-devel crypto-utils.* openssl* readline-devel pam-devel
  3. 압축 해제하고 , 컴파일 -> 설치 들어가기
    $> tar -zxvf postgresql-9.2.4.tar.gz
    $> cd postgresql-9.2.4
    ./configure \
    -&#45enable-nls=’ko’ \
    -&#45enable-depend \
    -&#45enable-thread-safety \
    --mandir=/usr/share/man \
    --with-includes=/usr/include \
    --with-pam \
    --with-openssl \
    --without-tcl \
    --without-perl \
    --without-python
    $> gmake ; gmake install
  4. postgres사용자 추가
    $> groupadd dba
    $> adduser -d /usr/local/pgsql -g dba -c “PostgreSQL Master User” -m -s $> /bin/bash postgres
    $> mkdir /usr/local/pgsql/data
    $> chown postgres /usr/local/pgsql/data
    $> chown -R postgres:dba /usr/local/pgsql
    $> cd /usr/local/pgsql
    $> chown -R root lib include
  5. 추가된 postgres sql 사용자에 대해서 postgessql 사용할수 있게 설정
    $> su – postgres
    $> echo "
    export MANPATH=\$HOME/man
    export PGDATA=/usr/local/pgsql/data
    export PATH=$PATH:/usr/local/pgsql/bin" >> /usr/local/pgsql/.bash_profile
    $> source /usr/local/pgsql/.bash_profile
    $> exit
  6. postgressql DB초기화 하기
    $> su - postgres -c "/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data"
  7. 재부팅 이후에도 실행할 수 있게 rc.local에 등록하기
    $> echo 'su – postgres -c "/usr/local/pgsql/bin/pg_ctl start -D /usr/local/pgsql/data/" &' >> /etc/rc.d/rc.local
  8. 네트워크에서 5432번 포트 열려있는지 확인
    $> netstat -antp
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
    ...
    tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 22435/postgres
    ...


adfit

AI들끼리 대화하기

ChatGPT, perplexity, Gemini... 많은 AI 서비스가 있고 서비스별로 다양한 엔진이 있죠. 문득 AI끼리 대화를 시켜보면 어떤 대화의 흐름을 이어갈까 궁금해졌습니다. 그래서 해보았습니다. 규 칙 나(사람)은 양쪽 AI에서...