首页 > 解决方案 > 我在 Docker 容器中找不到 postgresql 表

问题描述

有一个Java项目。这个项目不是我的。我正在努力对付他。有授权服务:

spring:
  profiles:
    active: @spring.profiles.active@
  jpa:
    hibernate:
      ddl-auto: none
  datasource:
    initialization-mode: always
    platform: authentication
    driver-class-name: org.postgresql.Driver
    username: postgres
    password: postgres
    url: jdbc:postgresql://localhost:5432/mark_authentication
    jdbc-url: jdbc:postgresql://localhost:5432/mark_authentication
  liquibase:
    change-log: classpath:db/changelog.xml

这是 liquibase 的文件

    <changeSet  id="create_roles"  author="afanasev">
        <createTable  tableName="roles" schemaName="users">
            <column  name="id"  type="BIGINT"  autoIncrement="true">
                <constraints  primaryKey="true"  nullable="false"/>
            </column>
            <column  name="role_name"  type="varchar(25)"/>
        </createTable>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="0"/>
            <column  name="role_name"  value="ROLE_SUBSCRIBER"/>
        </insert>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="1"/>
            <column  name="role_name"  value="ROLE_MARKETPLACE"/>
        </insert>
        <insert  schemaName="users"
                 tableName="roles">
            <column  name="id"  value="2"/>
            <column  name="role_name"  value="ROLE_ADMIN"/>
        </insert>
    </changeSet>
    <changeSet  id="create_users"  author="afanasev">
        <createTable  tableName="users" schemaName="users">
            <column  name="id"  type="VARCHAR(255)"  autoIncrement="false">
                <constraints  primaryKey="true"  nullable="false"/>
            </column>
            <column  name="password"  type="VARCHAR(50)">
                <constraints  nullable="false"/>
            </column>
            <column  name="email"  type="VARCHAR(50)">
                <constraints  nullable="false"/>
            </column>
            <column  name="full_name"  type="VARCHAR(255)">
                <constraints  nullable="false"/>
            </column>
            <column  name="is_active"  type="boolean" defaultValueBoolean="false">
                <constraints  nullable="false"/>
            </column>
            <column  name="date_added"  type="timestamp" defaultValueComputed="current_timestamp">
                <constraints  nullable="false"/>
            </column>
            <column  name="id_role"  type="INT">
                <constraints nullable="false" foreignKeyName="fk_role" referencedTableSchemaName="users" referencedTableName="roles" referencedColumnNames="id"/>
            </column>
            <column  name="code"  type="int"/>
        </createTable>
    </changeSet>
    <changeSet  id="update_users"  author="afanasev">
        <addColumn tableName="users" schemaName="users">
            <column name="address" type="VARCHAR(255)"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="tax_identification_number" type="BIGINT"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="organization" type="VARCHAR(255)"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="msisdn" type="BIGINT"/>
        </addColumn>
        <addColumn tableName="users" schemaName="users">
            <column name="code_reason" type="BIGINT"/>
        </addColumn>
    </changeSet>

这是 docker-compose 文件

  postgres-authentication:
    container_name: postgres-authentication
    image: postgres:13.2-alpine
    restart: unless-stopped
    ports:
      - "5433:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_DB=authentication
      - POSTGRES_PASSWORD=postgres
    volumes:
      - ./postgres_authentication_data:/var/lib/postgresql/data

该应用程序正在服务器上运行和旋转。我进入码头集装箱

docker exec -it postgres-authentication bash

连接到数据库

\c authentication

我在那里看不到任何表格,除了日志

\dt
Schema |         Name          | Type  |  Owner
--------+-----------------------+-------+----------
 public | databasechangelog     | table | postgres
 public | databasechangeloglock | table | postgres

我查看日志,更改日志在那里工作并且表已经创建。

create_roles | afanasev | db/changelog/01-create-user.xml | 2021-07-01 20:03:45.70403  |             1 | EXECUTED | 8:f576f05834bc714dda20a2e6580fd2de | createTable tableName=roles; insert tableName=roles; insert tableName=roles; insert tableName=roles                                   |          |     | 3.10.3    |          |        | 5169825313
create_users | afanasev | db/changelog/01-create-user.xml | 2021-07-01 20:03:46.039663 |             2 | EXECUTED | 8:f0f6055fe52f20bd3123bb53b38071de | createTable tableName=users                                                                                                           |          |     | 3.10.3    |          |        | 5169825313

事实上,我正在注册并且它可以工作,即它添加了一个用户,我可以在它下面登录。但是这些桌子在哪里呢?也许我不在那儿看?

标签: javaspringpostgresqldocker

解决方案


使用时\dt,默认只显示public架构

如果要显示所有架构表,则应使用\dtS或使用\dt [PATTERN]

如果使用\dtS,您会看到数据库的所有架构都包括 Postgres 架构,例如pg_catalog

但是如果使用\dt [PATTERN],您可以看到与您的预期匹配的模式模式。如下所示:

-- just show users schema
\dt users

推荐阅读