ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • H2 Server 설치, Error 해결
    Back-End/Database & etc 2022. 9. 5. 22:07
    Database may be already in use: null. Possible solutions: close all other connection(s); use the server mode

     이미 서버가 켜져 있는데 또 켜려고 하니, 생기는 에러.

     

    Database may be already in use: "Locked by another process"

     내장모드(Embedded)와 내 컴퓨터에 설치된 h2 Tcp/Ip 와 연결하여 실행시킬 수 있는 방법(Server)이 있다. 내장모드일 때에는 한 프로세스가 실행되고 있으면 다른 프로세스를 실행할 수 없기 때문에 여러 개를 실행하고 싶다면 Server 로 실행시켜줘야한다.

     

     

    아래는 최대한 충돌이 나지 않게 하기 위해 시도한 방법

    # Database
    spring:
      profiles:
        active: local
      datasource:
        driver-class-name: org.h2.Driver
        url:  jdbc:h2:[C드라이브부터 폴더 경로]\[.db로 생성되는 파일명];AUTO_SERVER=TRUE;
        username: 
        password: 
      jpa:
        # hibernate 설정
        hibernate:
          ddl-auto: create
        properties:
          hibernate:
            show_sql: true
            format_sql: true
      h2:
        console:
          enabled: true

    url을 .db가 생성될 폴더로 지정

    Server 로 실행되도록 TRUE 추가

     

     

    위 설명은 h2 Database 안내 문구를 토대로 작성하였다.

    H2 Database URLs

    Embedded
    The URL jdbc:h2:~/test means the database is stored in the user home directory in files starting with 'test'. Absolute locations like jdbc:h2:/data/db/test are supported. In embedded mode, the database runs in the same process as the application. Only one process may access a database at any time. Databases are automatically created if they don't exist. Warning: if no path is used (for example jdbc:h2:test), then the database is stored in the current working directory (the directory where the application was started). URLs of the form jdbc:h2:data/test are relative to the current working directory. It is recommended to use locations relative to ~ or absolute locations.

    Remote (client/server)
    The URL jdbc:h2:tcp://localhost/~/test means connect over TCP/IP to the H2 TCP server running on this computer, and open a database called test in the user home directory. The server must be started first. Any number of clients can connect to the same database. The same location rules as for embedded databases apply.

    In-Memory
    The URL jdbc:h2:mem:test means open an in-memory database named 'test'. Data is not persisted, and lost when the last connection to the database is closed. Multiple threads can access the same database, but data is only visible within the same process.

    'Back-End > Database & etc' 카테고리의 다른 글

    Yaml 을 Private 서브 모듈로 추가하여 관리하기  (0) 2023.06.08
    DTO, VO, Entity  (0) 2022.09.09
Designed by Tistory.