스키마 자체를 변경해서 어떻게 할 수 있을줄 알았는데 그건 안되고

테이블에 해당 schema 정보가 있기 때문에

table 별로 이동을 시켜주어야 한다.

 

동일 데이터베이스내면 그나마 다행인데.. 그게 아니라면 pg_dump로 뺴내서 데이터베이스간에 옮겨야 한다.

[링크 : https://www.codeproject.com/Questions/1020013/how-to-copy-table-one-database-to-another-database]

[링크 : https://www.postgresql.org/docs/9.1/sql-altertable.html]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql copy from csv, date null  (0) 2019.09.05
postgresql unknown pseudo-type  (0) 2019.09.05
pgadmin over ssh  (0) 2019.09.03
psql 명령어  (0) 2019.09.03
postgresql copy 와 \copy  (0) 2019.09.03
Posted by 구차니
Linux/Ubuntu2019. 9. 4. 15:18

설정이 꼬였나.. 기존에는 바로 된거 같은데 안되네?

 

$ sudo vim /etc/apache2/apache2.conf

Include /etc/phpmyadmin/apache.conf

$ sudo service apache2 restart

[링크 : https://tistory.woobi.org/52]

'Linux > Ubuntu' 카테고리의 다른 글

우분투 화상 키보드 끄기  (0) 2019.12.21
mx linux - xfce + debian  (0) 2019.10.14
ubuntu 18.04 wayland와 ubuntu session  (0) 2019.08.28
ubuntu virtual desktop  (0) 2019.08.28
ubuntu 18.04 fsck 예약(?)  (0) 2019.08.27
Posted by 구차니

compatible을 넣는다고 해서 해당 compatible mode의 주석처리나 변수형이 바뀌진 않는다.. 인가?

 

--compatible=name

Produce output that is more compatible with other database systems or with older MySQL servers. The value of name can be ansi, mysql323,mysql40, postgresql, oracle, mssql, db2, maxdb, no_key_options, no_table_options, or no_field_options. To use several values, separate them by commas. These values have the same meaning as the corresponding options for setting the server SQL mode. See Section 5.1.10, “Server SQL Modes”.

This option does not guarantee compatibility with other servers. It only enables those SQL mode values that are currently available for making dump output more compatible. For example, --compatible=oracle does not map data types to Oracle types or use Oracle comment syntax.

[링크 : https://dev.mysql.com/doc/refman/5.5/en/mysqldump.html]

[링크 : https://dev.mysql.com/doc/refman/5.5/en/sql-mode.html]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

HeidiSQL  (2) 2021.08.18
sql zerofill  (0) 2019.11.25
mysql / unix-socket  (0) 2019.09.04
mysql exists  (0) 2019.07.05
mysql timestamp 1분 이내 매치하기  (0) 2018.12.21
Posted by 구차니

그냥 root 권한은 유닉스 소켓으로 접속하게 되어있어서

sudo 를 통해 권한을 변경해서 접속하면 된다고... -_-

 

$ sudo mysql -u root

[링크 : https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

sql zerofill  (0) 2019.11.25
mysql-dump compatible 함정 -_-  (0) 2019.09.04
mysql exists  (0) 2019.07.05
mysql timestamp 1분 이내 매치하기  (0) 2018.12.21
mysql join과 필드명 변경하기  (0) 2018.12.21
Posted by 구차니

거창한건 아니고 리눅스에서 -L 옵션을 통해 ssh의 포트포워딩으로 

localhost 포트를 통해 접속하는 것. 나름 속도도 잘나오고 좋네

 

[링크 :  https://www.tecmint.com/create-ssh-tunneling-port-forwarding-in-linux/]

[링크 :  https://www.linode.com/.../how-to-access-postgresql-database-remotely-using-pgadmin-on-windows/]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql unknown pseudo-type  (0) 2019.09.05
postgresql schema 내의 테이블 이동하기  (0) 2019.09.05
psql 명령어  (0) 2019.09.03
postgresql copy 와 \copy  (0) 2019.09.03
pg_restore  (0) 2019.09.03
Posted by 구차니

\dt 밖에 기억을 못하고 살아서 좀더 봐야 할 듯

 

정보보기
  (옵션: S = 시스템 개체 표시, + = 추가 상세 정보)
  \d[S+]                 테이블, 뷰 및 시퀀스 목록
  \d[S+]  NAME           테이블, 뷰, 시퀀스 또는 인덱스 설명
  \da[S]  [PATTERN]      집계 함수 목록
  \dA[+]  [PATTERN]      접근 방법 목록
  \db[+]  [PATTERN]      테이블스페이스 목록
  \dc[S+] [PATTERN]      문자셋 변환자 목록
  \dC[+]  [PATTERN]      자료형 변환자 목록
  \dd[S]  [PATTERN]      다른 곳에서는 볼 수 없는 객체 설명을 보여줌
  \dD[S+] [PATTERN]      도메인 목록
  \ddp    [PATTERN]      기본 접근권한 목록
  \dE[S+] [PATTERN]      외부 테이블 목록
  \det[+] [PATTERN]      외부 테이블 목록
  \des[+] [PATTERN]      외부 서버 목록
  \deu[+] [PATTERN]      사용자 매핑 목록
  \dew[+] [PATTERN]      외부 데이터 래퍼 목록
  \df[anptw][S+] [PATRN] [agg/normal/procedures/trigger/window] 함수 목록
  \dF[+]  [PATTERN]      텍스트 검색 구성 목록
  \dFd[+] [PATTERN]      텍스트 검색 사전 목록
  \dFp[+] [PATTERN]      텍스트 검색 파서 목록
  \dFt[+] [PATTERN]      텍스트 검색 템플릿 목록
  \dg[S+] [PATTERN]      롤 목록
  \di[S+] [PATTERN]      인덱스 목록
  \dl                    큰 개체 목록, \lo_list 명령과 같음
  \dL[S+] [PATTERN]      프로시져 언어 목록
  \dm[S+] [PATTERN]      materialized 뷰 목록
  \dn[S+] [PATTERN]      스키마 목록
  \do[S]  [PATTERN]      연산자 목록
  \dO[S+] [PATTERN]      collation 목록
  \dp     [PATTERN]      테이블, 뷰 및 시퀀스 액세스 권한 목록
  \drds [PATRN1 [PATRN2]] 데이터베이스별 롤 설정 목록
  \dRp[+] [PATTERN]      복제 발행 목록
  \dRs[+] [PATTERN]      복제 구독 목록
  \ds[S+] [PATTERN]      시퀀스 목록
  \dt[S+] [PATTERN]      테이블 목록
  \dT[S+] [PATTERN]      데이터 형식 목록
  \du[S+] [PATTERN]      롤 목록
  \dv[S+] [PATTERN]      뷰 목록
  \dx[+]  [PATTERN]      확장 모듈 목록

  \dy     [PATTERN]      이벤트 트리거 목록
  \l[+]   [PATTERN]      데이터베이스 목록
  \sf[+]  함수이름       함수 정의 보기
  \sv[+] 뷰이름          뷰 정의 보기
  \z      [PATTERN]      \dp와 같음

 

전체 스키마 목록

\dn

[링크 : https://tableplus.com/blog/2018/04/postgresql-how-to-list-all-schemas.html]

 

기본은 public schema만 보도록 되어있어서

show search_path;를 통해 현재 설정된 것을 보고

set search_path = newschema;를 통해서 newschema를 기본으로 보게 된다(\dt 등의 결과가 영향을 받음)

[링크 : https://www.mkyong.com/database/postgresql-how-to-change-default-schema/]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

postgresql schema 내의 테이블 이동하기  (0) 2019.09.05
pgadmin over ssh  (0) 2019.09.03
postgresql copy 와 \copy  (0) 2019.09.03
pg_restore  (0) 2019.09.03
postgresql working directory  (0) 2019.09.02
Posted by 구차니

copy는 SQL 문의 명령어 이고

[링크 : https://www.postgresql.org/docs/9.2/sql-copy.html]

 

\copy는 psql에서 인식하는 meta command 라고..

[링크 : https://www.postgresql.org/docs/9.2/app-psql.html]

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

pgadmin over ssh  (0) 2019.09.03
psql 명령어  (0) 2019.09.03
pg_restore  (0) 2019.09.03
postgresql working directory  (0) 2019.09.02
postgresql \copy에서 컬럼 무시하기  (0) 2019.09.02
Posted by 구차니

원하는 내용만을 빼낼수는 있는 듯?

그나저나.. 특정 schema에 넣으려고 했는데 왜 안되지.. ㅠㅠ

 

[링크 : http://i5on9i.blogspot.com/2016/09/db-pgdump-pgrestore.html]

[링크 : https://www.postgresql.org/docs/9.2/app-pgrestore.html]

[링크 : https://stackoverflow.com/questions/4191653/i-want-to-restore-the-database-with-a-different-schema]

 

옵션을 봐도.. schema만 복구하는 등의 옵션은 있지만

특정 스키마로 복구하는 옵션은 존재하지 않는듯.

하고 나서 alter 로 변경해야 할것으로 보인다.

$ pg_restore --help
pg_restore 프로그램은 pg_dump로 만들어진 자료파일로 PostgreSQL 데이터베이스에
그 자료를 일괄 입력합니다.

사용법:
  pg_restore [옵션]... [파일]

일반 옵션들:
  -d, --dbname=NAME        접속할 데이터베이스 이름
  -f, --file=FILENAME      출력 파일 이름
  -F, --format=c|d|t       백업 파일 형식 (지정하지 않으면 자동분석)
  -l, --list               자료의 요약된 목차를 보여줌
  -v, --verbose            자세한 정보 보여줌
  -V, --version            버전 정보를 보여주고 마침
  -?, --help               이 도움말을 보여주고 마침

리스토어 처리를 위한 옵션들:
  -a, --data-only              스키마는 빼고 자료만 입력함
  -c, --clean                  다시 만들기 전에 데이터베이스 개체 지우기(삭제)
  -C, --create                 작업 대상 데이터베이스를 만듦
  -e, --exit-on-error          오류가 생기면 끝냄, 기본은 계속 진행함
  -I, --index=NAME             지정한 인덱스 만듦
  -j, --jobs=NUM               여러 병렬 작업을 사용하여 복원
  -L, --use-list=FILENAME      출력을 선택하고 해당 순서를 지정하기 위해
                               이 파일의 목차 사용
  -n, --schema=NAME            해당 스키마의 개체들만 복원함
  -N, --exclude-schema=NAME    해당 스키마의 개체들은 복원 안함
  -O, --no-owner               개체 소유권 복원 건너뛰기
  -P, --function=NAME(args)    지정한 함수 만듦
  -s, --schema-only            자료구조(스키마)만 만듦
  -S, --superuser=NAME         트리거를 사용하지 않기 위해 사용할 슈퍼유저
                               사용자 이름
  -t, --table=NAME             복원할 객체 이름 (테이블, 뷰, 기타)
  -T, --trigger=NAME           지정한 트리거 만듦
  -x, --no-privileges          접근 권한(grant/revoke) 지정 안함
  -1, --single-transaction     하나의 트랜잭션 작업으로 복원함
  --disable-triggers           자료만 복원할 때 트리거 사용을 안함
  --enable-row-security        로우 보안 활성화
  --if-exists                  객체 삭제 시 IF EXISTS 구문 사용
  --no-comments                코멘트는 복원하지 않음
  --no-data-for-failed-tables  만들 수 없는 테이블에 대해서는 자료를 덤프하지 않음
  --no-publications            발행 정보는 복원 안함
  --no-security-labels         보안 라벨을 복원하지 않음
  --no-subscriptions           구독 정보는 복원 안함
  --no-tablespaces             테이블스페이스 할당을 복원하지 않음
  --section=SECTION            지정한 섹션만 복원함
                               섹션 종류: pre-data, data, post-data
  --strict-names               테이블이나 스키마를 지정했을 때 그 패턴에 맞는
                               객체가 적어도 하나 이상 있어야 함
  --use-set-session-authorization
                               SET SESSION AUTHORIZATION 명령을 ALTER OWNER 명령
                               대신 사용하여 소유권 설정

연결 옵션들:
  -h, --host=HOSTNAME      접속할 데이터베이스 서버 또는 소켓 디렉터리
  -p, --port=PORT          데이터베이스 서버의 포트 번호
  -U, --username=NAME      연결할 데이터베이스 사용자
  -w, --no-password        암호 프롬프트 표시 안 함
  -W, --password           암호 입력 프롬프트 보임(자동으로 처리함)
  --role=ROLENAME          복원 전에 SET ROLE 수행

The options -I, -n, -N, -P, -t, -T, and --section can be combined and specified
multiple times to select multiple objects.

사용할 입력 파일을 지정하지 않았다면, 표준 입력(stdin)을 사용합니다.

오류보고: <pgsql-bugs@postgresql.org>.

 

결론은.. WAL을 활성화 시키고 그걸 쓰면 최대한 올릴수 잇고

8.4 이후 부터 병렬처리 옵션을 지원하니 그걸 쓰라고.. (일단은 하드불이 안꺼지는거 봐서는 WAL이 좀더 도움이 될 듯..)

First check that you are getting reasonable IO performance from your disk setup. Then check that you PostgreSQL installation is appropriately tuned. In particular shared_buffers should be set correctly, maintenance_work_mem should be increased during the restore, full_page_writes should be off during the restore, wal_buffers should be increased to 16MB during the restore, checkpoint_segments should be increased to something like 16 during the restore, you shouldn't have any unreasonable logging on (like logging every statement executed), auto_vacuum should be disabled during the restore.

If you are on 8.4 also experiment with parallel restore, the --jobs option for pg_restore.

[링크 : https://stackoverflow.com/questions/2094963/postgresql-improving-pg-dump-pg-restore-performance]

 

+

위의 옵션들을 건드리고 -j 4 로 해서 수행하니 40분 걸렸네..

938M  8월  1 15:48 postgres_data.dmp

938MB.. 정상 속도인건가? 아무튼 SSHD라 어느정도 넘어가면 HDD 속도에 늦어져서 그럴지도

real    39m28.317s
user    0m36.639s
sys     0m2.967s

 

+

SQL dump는 이렇게 빨리 되네.. -_-

(용량이 위는 900MB 아래는 500MB 지만)

real    2m55.319s
user    0m1.206s
sys     0m0.573s

 

+

--------+----------------------------+--------+----------+------------+------
 ctgov  | baseline_counts            | 테이블 | postgres | 8072 kB    | 
 ctgov  | baseline_measurements      | 테이블 | postgres | 159 MB     | 
 ctgov  | brief_summaries            | 테이블 | postgres | 200 MB     | 
 ctgov  | browse_conditions          | 테이블 | postgres | 45 MB      | 
 ctgov  | browse_interventions       | 테이블 | postgres | 24 MB      | 
 ctgov  | calculated_values          | 테이블 | postgres | 29 MB      | 
 ctgov  | central_contacts           | 테이블 | postgres | 13 MB      | 
 ctgov  | conditions                 | 테이블 | postgres | 45 MB      | 
 ctgov  | countries                  | 테이블 | postgres | 24 MB      | 
 ctgov  | criteria                   | 테이블 | postgres | 8192 bytes | 
 ctgov  | design_group_interventions | 테이블 | postgres | 34 MB      | 
 ctgov  | design_groups              | 테이블 | postgres | 114 MB     | 
 ctgov  | design_outcomes            | 테이블 | postgres | 451 MB     | 
 ctgov  | designs                    | 테이블 | postgres | 37 MB      | 
 ctgov  | detailed_descriptions      | 테이블 | postgres | 301 MB     | 
 ctgov  | documents                  | 테이블 | postgres | 2096 kB    | 
 ctgov  | drop_withdrawals           | 테이블 | postgres | 26 MB      | 
 ctgov  | eligibilities              | 테이블 | postgres | 407 MB     | 
 ctgov  | facilities                 | 테이블 | postgres | 241 MB     | 
 ctgov  | facility_contacts          | 테이블 | postgres | 28 MB      | 
 ctgov  | facility_investigators     | 테이블 | postgres | 17 MB      | 
 ctgov  | id_information             | 테이블 | postgres | 30 MB      | 
 ctgov  | intervention_other_names   | 테이블 | postgres | 18 MB      | 
 ctgov  | interventions              | 테이블 | postgres | 103 MB     | 
 ctgov  | ipd_information_types      | 테이블 | postgres | 856 kB     | 
 ctgov  | keywords                   | 테이블 | postgres | 71 MB      | 
 ctgov  | links                      | 테이블 | postgres | 7824 kB    | 
 ctgov  | mesh_headings              | 테이블 | postgres | 1128 kB    | 
 ctgov  | mesh_terms                 | 테이블 | postgres | 5920 kB    | 
 ctgov  | milestones                 | 테이블 | postgres | 34 MB      | 
 ctgov  | outcome_analyses           | 테이블 | postgres | 50 MB      | 
 ctgov  | outcome_analysis_groups    | 테이블 | postgres | 18 MB      | 
 ctgov  | outcome_counts             | 테이블 | postgres | 55 MB      | 
 ctgov  | outcome_measurements       | 테이블 | postgres | 1291 MB    | 
 ctgov  | outcomes                   | 테이블 | postgres | 178 MB     | 
 ctgov  | overall_officials          | 테이블 | postgres | 38 MB      | 
 ctgov  | participant_flows          | 테이블 | postgres | 7984 kB    | 
 ctgov  | pending_results            | 테이블 | postgres | 1712 kB    | 
 ctgov  | provided_documents         | 테이블 | postgres | 1480 kB    | 
 ctgov  | reported_events            | 테이블 | postgres | 1787 MB    | 
 ctgov  | responsible_parties        | 테이블 | postgres | 26 MB      | 
 ctgov  | result_agreements          | 테이블 | postgres | 15 MB      | 
 ctgov  | result_contacts            | 테이블 | postgres | 5120 kB    | 
 ctgov  | result_groups              | 테이블 | postgres | 273 MB     | 
 ctgov  | sponsors                   | 테이블 | postgres | 44 MB      | 
 ctgov  | studies                    | 테이블 | postgres | 186 MB     | 
 ctgov  | study_references           | 테이블 | postgres | 128 MB     | 

 

'프로그램 사용 > postgreSQL' 카테고리의 다른 글

psql 명령어  (0) 2019.09.03
postgresql copy 와 \copy  (0) 2019.09.03
postgresql working directory  (0) 2019.09.02
postgresql \copy에서 컬럼 무시하기  (0) 2019.09.02
postgresql \copy에서 시작 몇줄 무시하기  (0) 2019.09.02
Posted by 구차니
Linux2019. 9. 2. 19:06

특정필드를 날릴려면 미리 다른데 저장을 하고 =""으로 지정하면 되겠네?

 

$ awk '/Aaron/{ first_name=$2 ; second_name=$3 ; print first_name, second_name ; }' names.txt

[랑크 : https://www.tecmint.com/learn-awk-variables-numeric-expressions-and-assignment-operators/]

'Linux' 카테고리의 다른 글

csv에서는 awk 보단 cut  (0) 2019.09.05
awk csv  (0) 2019.09.05
awk 치환(삭제)  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
Posted by 구차니
Linux2019. 9. 2. 19:05

항상 그렇지만...

삭제는 ""으로 치환하는거고 그 함수로 sub와 gsub를 지원하는 듯

 

sub

cat my_list.txt | awk -F '\t' -v OFS='\t' '{ sub("-",".",$3); print }'

[링크 : http://bahndal.egloos.com/565881]

 

gsub

awk -F\, '{gsub(/[ \t]+$/, "", $2); print $2 ":"}'

[링크 : https://stackoverflow.com/questions/9985528/how-can-i-trim-white-space-from-a-variable-in-awk]

 

sub는 처음 매칭되는 것만 치환, gsub는 전역 치환인듯

sub(r, s [, t])

Just like gsub(), but only the first matching substring is replaced.

gsub(r, s [, t])

For each substring matching the regular expression r in the string t, substitute the string s, and return the number of substitutions. If t is not supplied, use $0. An & in the replacement text is replaced with the text that was actually matched. Use \& to get a literal &. (This must be typed as "\\&"; see GAWK: Effective AWK Programming for a fuller discussion of the rules for &'s and backslashes in the replacement text of sub(), gsub(), and gensub().)

[링크 : https://linux.die.net/man/1/awk]

'Linux' 카테고리의 다른 글

awk csv  (0) 2019.09.05
awk 변수 지정  (0) 2019.09.02
tail과 cat 합치기  (0) 2019.09.02
awk 구분자 탭으로 인식시키기  (0) 2019.09.02
awk 특정 열 제외하기  (0) 2019.09.02
Posted by 구차니