PostgreSQL에서 데이터베이스 스키마를 내보내려면 어떻게 해야 합니까?
컴퓨터가 고장났지만 다행히 C:\Program Files\Postgre 폴더를 백업했습니다.SQL.
현재 새 컴퓨터에서 작업 중이며 외부 디스크에 저장된 이전 Postgres 데이터베이스를 가져오려고 합니다.
백업 폴더에 있는 특정 데이터베이스의 스키마를 내보냅니다.
파일PostgreSQL\8.3\data\global\pg_database에는 데이터베이스 및 데이터베이스 OID에 대한 정보가 포함되어 있습니다. 예:
"db1" 20012
"db2" 23456
"db1"의 스키마를 내보내고 싶습니다.
폴더에 "20012"라는 이름의 폴더가 있습니다."PostgreSQL\8.3\data\base\20012"파일이 많이 들어 있습니다[500개 파일].
그 데이터베이스의 스키마를 내보낼 방법이 있습니까?
모든 Postgresql 데이터베이스 파일은 외부 하드 디스크에 있습니다. 이 데이터베이스의 스키마를 SQL 파일로 내보내고, 해당 파일을 가져와서 실행하고, 동일한 정확한 데이터베이스를 로컬로 생성합니다.
당신은 이것을 봐야 합니다.pg_dump:
pg_dump --schema-only databasename
.sql로 stdout할 스키마만 덤프합니다.
윈도우의 경우, 아마도 전화를 하고 싶을 것입니다.pg_dump.exeWindows 컴퓨터에 액세스할 수는 없지만 메모리를 보면 명령어라고 확신합니다.도움이 당신에게도 효과가 있는지 확인하세요.
저는 데이터와 함께 특정 스키마를 내보내야 하는 Postgres 9.6을 실행하고 있습니다.
다음 명령을 사용했습니다.
pg_dump.exe -U username -d databasename -n schemaname > C:\mylocation\mydumpfilename.dmp
데이터 없이 스키마만 사용하려면 스위치를 사용합니다.s대신에n
다음은 pg_dump 스위치 목록입니다.
C:\Program Files\PostgreSQL\9.6\bin>pg_dump --help
pg_dump dumps a database as a text file or to other formats.
Usage:
pg_dump [OPTION]... [DBNAME]
General options:
-f, --file=FILENAME output file or directory name
-F, --format=c|d|t|p output file format (custom, directory, tar,
plain text (default))
-j, --jobs=NUM use this many parallel jobs to dump
-v, --verbose verbose mode
-V, --version output version information, then exit
-Z, --compress=0-9 compression level for compressed formats
--lock-wait-timeout=TIMEOUT fail after waiting TIMEOUT for a table lock
-?, --help show this help, then exit
Options controlling the output content:
-a, --data-only dump only the data, not the schema
-b, --blobs include large objects in dump
-c, --clean clean (drop) database objects before recreating
-C, --create include commands to create database in dump
-E, --encoding=ENCODING dump the data in encoding ENCODING
-n, --schema=SCHEMA dump the named schema(s) only
-N, --exclude-schema=SCHEMA do NOT dump the named schema(s)
-o, --oids include OIDs in dump
-O, --no-owner skip restoration of object ownership in
plain-text format
-s, --schema-only dump only the schema, no data
-S, --superuser=NAME superuser user name to use in plain-text format
-t, --table=TABLE dump the named table(s) only
-T, --exclude-table=TABLE do NOT dump the named table(s)
-x, --no-privileges do not dump privileges (grant/revoke)
--binary-upgrade for use by upgrade utilities only
--column-inserts dump data as INSERT commands with column names
--disable-dollar-quoting disable dollar quoting, use SQL standard quoting
--disable-triggers disable triggers during data-only restore
--enable-row-security enable row security (dump only content user has
access to)
--exclude-table-data=TABLE do NOT dump data for the named table(s)
--if-exists use IF EXISTS when dropping objects
--inserts dump data as INSERT commands, rather than COPY
--no-security-labels do not dump security label assignments
--no-synchronized-snapshots do not use synchronized snapshots in parallel jobs
--no-tablespaces do not dump tablespace assignments
--no-unlogged-table-data do not dump unlogged table data
--quote-all-identifiers quote all identifiers, even if not key words
--section=SECTION dump named section (pre-data, data, or post-data)
--serializable-deferrable wait until the dump can run without anomalies
--snapshot=SNAPSHOT use given snapshot for the dump
--strict-names require table and/or schema include patterns to
match at least one entity each
--use-set-session-authorization
use SET SESSION AUTHORIZATION commands instead of
ALTER OWNER commands to set ownership
Connection options:
-d, --dbname=DBNAME database to dump
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port number
-U, --username=NAME connect as specified database user
-w, --no-password never prompt for password
-W, --password force password prompt (should happen automatically)
--role=ROLENAME do SET ROLE before dump
If no database name is supplied, then the PGDATABASE environment
variable value is used.
Report bugs to <pgsql-bugs@postgresql.org>.
Linux에서는 다음과 같이 할 수 있습니다.
pg_dump -U postgres -s postgres > exportFile.dmp
pg_dump.exe와 동일하게 시도하지 않으면 Windows에서도 작동할 수 있습니다.
pg_dump.exe -U postgres -s postgres > exportFile.dmp
pg_dump -d <databasename> -h <hostname> -p <port> -n <schemaname> -f <location of the dump file>
해당 스키마에 액세스할 수 있는 충분한 권한이 있습니다.특정 사용자로 백업을 수행하려면 다음 명령 앞에 사용자 이름을 추가합니다.-U
Linux의 경우: (데이터 제외)
pg_dump -s -t tablename databasename > dump.sql(데이터베이스의 특정 테이블의 경우)pg_dump -s databasename > dump.sql(전체 데이터베이스에 대해)
테이블 작성만 원하는 경우 다음 작업을 수행할 수 있습니다.pg_dump -s databasename | awk 'RS="";/CREATE TABLE[^;]*;/'
이런 것을 사용해야 합니다.pg_dump --schema=your_schema_name db1자세한 내용은 여기를 참조하십시오.
pg_dump -s databasename -t tablename -U user -h host -p port > tablename.sql
스키마 덤프를 "tablename" 테이블의 "tablename"으로 제한합니다.
새 postgresql 서버를 설정하고 해당 데이터 폴더를 외부 디스크의 파일로 바꿉니다.
그러면 pg_dump를 사용하여 해당 postgresql 서버를 시작하고 데이터를 검색할 수 있습니다(앞에서 설명한 대로 스키마 전용의 pg_dump -s).
언급URL : https://stackoverflow.com/questions/14486241/how-can-i-export-the-schema-of-a-database-in-postgresql
'programing' 카테고리의 다른 글
| LINQ를 사용하여 목록이 비어 있는지 확인하는 중 (0) | 2023.05.09 |
|---|---|
| 두 기준의 모든 조합을 반환하면서 여러 기준에 가입하는 방법은 무엇입니까? (0) | 2023.05.09 |
| WPF 응용 프로그램에서 리소스 '기본 창'을 찾을 수 없습니다.xaml' (0) | 2023.05.09 |
| npm - 패키지의 최신 버전을 표시하는 방법 (0) | 2023.05.09 |
| 윈도우즈 호스트 파일의 와일드카드 (0) | 2023.05.09 |