2024-03-01 09:12PM
1. 先查看正在运行的容器列表:
docker ps
eg:
root@ali-anquan-2:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4510a9e8d123 postgres "docker-entrypoint.s…" 8 weeks ago Up 18 minutes 5432/tcp objective_jang
2. 使用命令来进入PostgreSQL容器的命令行终端:
docker exec -it <容器ID或名称> /bin/bash
eg:
root@ali-anquan-2:~# docker exec -it 4510a9e8d123 bash
3. 登录PostgreSQL数据库:
root@4510a9e8d123:/# psql -U postgres -d postgres
4.使用 \l
命令查看当前数据库服务器中的所有数据库列表
postgres=# \l
List of databases
Name | Owner | Encoding | Locale Provider | Collate | Ctype | ICU Locale | ICU Rules | Access privileges
----------------+----------+----------+-----------------+------------+------------+------------+-----------+-----------------------
dongtaipaifang | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
postgres | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | |
template0 | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | libc | en_US.utf8 | en_US.utf8 | | | =c/postgres +
| | | | | | | | postgres=CTc/postgres
(4 rows)
5. \c <数据库名称>
命令切换到正确的数据库
postgres=# \c dongtaipaifang
You are now connected to database "dongtaipaifang" as user "postgres".
6. \dt <模式名称>.*
命令可以查看特定模式下的所有表
dongtaipaifang=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------------------+-------+----------
public | calculation_plans | table | postgres
public | calculation_plans_materials | table | postgres
public | calculation_result_details | table | postgres
public | calculation_results | table | postgres
public | calculation_templates | table | postgres
public | datasets | table | postgres
public | history_login_logs | table | postgres
public | materials | table | postgres
public | users | table | postgres
public | verification_codes | table | postgres
(10 rows)
7. 下面这个命令可以查看表信息,包括列名、数据类型和约束 :
\dt+ <表名称>
eg:
dongtaipaifang=# \dt+calculation_templates
List of relations
Schema | Name | Type | Owner | Table | Persistence | Access method | Size | Description
--------+------------------------------------+----------+----------+-----------------------------+-------------+---------------+------------+-------------
public | calculation_plans | table | postgres | | permanent | heap | 240 kB |
public | calculation_plans_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | calculation_plans_materials | table | postgres | | permanent | heap | 8192 bytes |
public | calculation_plans_materials_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | calculation_plans_materials_pkey | index | postgres | calculation_plans_materials | permanent | btree | 8192 bytes |
public | calculation_plans_pkey | index | postgres | calculation_plans | permanent | btree | 16 kB |
public | calculation_result_details | table | postgres | | permanent | heap | 2192 kB |
public | calculation_result_details_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | calculation_result_details_pkey | index | postgres | calculation_result_details | permanent | btree | 56 kB |
public | calculation_results | table | postgres | | permanent | heap | 48 kB |
public | calculation_results_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | calculation_results_pkey | index | postgres | calculation_results | permanent | btree | 16 kB |
public | calculation_templates | table | postgres | | permanent | heap | 48 kB |
public | calculation_templates_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | calculation_templates_pkey | index | postgres | calculation_templates | permanent | btree | 16 kB |
public | datasets | table | postgres | | permanent | heap | 88 kB |
public | datasets_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | datasets_pkey | index | postgres | datasets | permanent | btree | 16 kB |
public | history_login_logs | table | postgres | | permanent | heap | 72 kB |
public | history_login_logs_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | history_login_logs_pkey | index | postgres | history_login_logs | permanent | btree | 32 kB |
public | materials | table | postgres | | permanent | heap | 16 kB |
public | materials_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | materials_pkey | index | postgres | materials | permanent | btree | 16 kB |
public | users | table | postgres | | permanent | heap | 16 kB |
public | users_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | users_pkey | index | postgres | users | permanent | btree | 16 kB |
public | verification_codes | table | postgres | | permanent | heap | 16 kB |
public | verification_codes_id_seq | sequence | postgres | | permanent | | 8192 bytes |
public | verification_codes_pkey | index | postgres | verification_codes | permanent | btree | 16 kB |
(30 rows)
8. \d
命令可以查看某一个表的列
dongtaipaifang=# \d calculation_templates
Table "public.calculation_templates"
Column | Type | Collation | Nullable | Default
-------------------------------------+--------------------------+-----------+----------+---------------------------------------------------
id | integer | | not null | nextval('calculation_templates_id_seq'::regclass)
name | text | | |
explain | text | | |
algorithm_name | text | | |
initial_discharge_rate | numeric | | not null |
initial_filling_amount | numeric | | not null |
operating_discharge_rate | numeric | | not null |
maintenance_discharge_rate | numeric | | not null |
maintenance_filling_rate | numeric | | not null |
annual_maintenance_rate | numeric | | not null |
scrap_discharge_rate | numeric | | not null |
created_at | timestamp with time zone | | |
updated_at | timestamp with time zone | | |
english_name | text | | |
factor_tui_yi | numeric | | |
factor_by_year | numeric | | |
factor_production | numeric | | |
initial_discharge_rate_years | text | | |
initial_filling_amount_years | text | | |
operating_discharge_rate_years | text | | |
maintenance_discharge_rate_years | text | | |
maintenance_filling_rate_years | text | | |
annual_maintenance_rate_years | text | | |
scrap_discharge_rate_years | text | | |
factor_tui_yi_years | text | | |
factor_by_year_years | text | | |
factor_production_years | text | | |
refrigeration_params_data | text | | |
foam_params_data | text | | |
annual_scrap_rate | numeric | | |
accumulated_scrap_rate_year_by_year | numeric | | |
hfc_emission_rate | numeric | | |
life | integer | | |
room_refrigeration_params_data | text | | |
Indexes:
"calculation_templates_pkey" PRIMARY KEY, btree (id)
登录
请登录后再发表评论。
评论列表:
目前还没有人发表评论