Postgresql - SQLite 로부터 가져오기

2023. 7. 23. 02:01DB/postgresql

 

-------------------------------->

 

준비물 :

  • pgloader 실행파일 (또는 패키지) 설치
  • 가져올 SQLite DB파일
  • 대상 postgresql 서버 정보 (사용계정, 호스트 IP:PORT)

데비안의 경우 pgloader 는 따로 설치해야 한다.


작업 방법 :

DBeaver 를 설치하면 만들어주는 연습용 테이블(SQLite)을 postgresql DB 로 옮기는 명령은 다음과 같다.

 

pgloader(명령어) sqlite:///{SQLite DB파일 절대경로} pgsql://{postgres계정정보}@{postgres 호스트 정보}/{DB명}

 

 

실제 실행결과 :

/home/user/EXAMPLE/sample-database-sqlite-1/Chinook.db pgsql://postgres:postgres@localhost:5432/postgres
---
[실행결과]
2023-07-22T17:16:09.020000Z LOG pgloader version "3.6.7~devel"
2023-07-22T17:16:09.024000Z LOG Data errors in '/tmp/pgloader/'
2023-07-22T17:16:09.096001Z LOG Migrating from #<SQLITE-CONNECTION sqlite:///home/user/EXAMPLE/sample-database-sqlite-1/Chinook.db {1005DB3B63}>
2023-07-22T17:16:09.096001Z LOG Migrating into #<PGSQL-CONNECTION pgsql://postgres@localhost:5432/postgres {1005F89F13}>
2023-07-22T17:16:10.044011Z LOG report summary reset
             table name     errors       rows      bytes      total time
-----------------------  ---------  ---------  ---------  --------------
                  fetch          0          0                     0.000s
        fetch meta data          0         56                     0.056s
         Create Schemas          0          0                     0.000s
       Create SQL Types          0          0                     0.004s
          Create tables          0         24                     0.056s
         Set Table OIDs          0         12                     0.012s
-----------------------  ---------  ---------  ---------  --------------
                  album          0        347    77.0 kB          0.148s
                 artist          0        275     6.8 kB          0.132s
               customer          0         59     6.7 kB          0.188s
                  genre          0         25     0.3 kB          0.232s
            invoiceline          0       2240    43.6 kB          0.324s
               playlist          0         18     0.3 kB          0.292s
                  track          0       3503   236.6 kB          0.408s
               employee          0          8     1.4 kB          0.004s
                invoice          0        412    31.0 kB          0.068s
              mediatype          0          5     0.1 kB          0.064s
          playlisttrack          0       8715    57.3 kB          0.208s
                    foo          0          0                     0.128s
-----------------------  ---------  ---------  ---------  --------------
COPY Threads Completion          0          4                     0.448s
         Create Indexes          0         33                     0.252s
 Index Build Completion          0         33                     0.148s
        Reset Sequences          0          0                     0.040s
           Primary Keys          0         11                     0.008s
    Create Foreign Keys          0         11                     0.020s
        Create Triggers          0          0                     0.000s
       Install Comments          0          0                     0.000s
-----------------------  ---------  ---------  ---------  --------------
      Total import time          ✓      15607   461.0 kB          0.916s

 

마이그레이션 성공!!


유의할 점 :

  • postgres 계정정보를 적을 때 패스워드도 함께 지정해주어야 한다. "계정:패스워드@호스트정보"
  • 이 부분은 인터넷 프로토콜을 지정할 때 공통적으로 쓰이는 양식인 것 같다.
  • pgsql://postgres:postgres@localhost:5432/postgres

패스워드를 지정하지 않으면 별도로 패스워드 입력 프롬프트가 뜨지 않고 오류 메시지를 뱉어 낸다.

 

참고한 문서 :

 

SQLite to Postgres — pgloader 3.6.9 documentation

SQLite to Postgres This command instructs pgloader to load data from a SQLite file. Automatic discovery of the schema is supported, including build of the indexes. Using default settings Here is the simplest command line example, which might be all you nee

pgloader.readthedocs.io

 

'DB > postgresql' 카테고리의 다른 글

Postgresql - 계정 패스워드 변경하기  (0) 2023.07.12
Postgresql - DB 사용자 계정 생성  (0) 2023.07.10
Postgresql 관리자 로그인 설정  (0) 2023.07.09