Giriş
Kabuk açıldıktan sonra komut çalıştırmak içindir.
Genel
\l (List) ile veri tabanları listelenir
\c (Connect) dbname ile veri tabanına bağlanılır
\d (Describe) ile tablo yapısı incelenebilir
\dt (Describe Tables) ile tablolar listelenir
\di (Describe Index) ile indeksler listelenir
\q - quit
Kabuktan çıkmak içindir
Kabuktan çıkmak içindir
\c [database] veya \connect [database] seçeneği - Connect to a different database
Bir veri tabanına bağlanır. Kısa hali \c şeklindedir.
Örnek
payment isimli bir veri tabanı olsun. Şöyle yaparız. Bu komuttan sonra prompt'un veri tabanı ismi olduğu görülebilir.
postgre#\c payment
You are not connected to database 'payment' as "...".
payment#
Örnek
Şöyle yaparız. Burada postgres veri tabanına bağlıydık. \c ile myjhipsterplanet veri tabanına bağlandık. Ayrıca hangi kullanıcı olarak bağlandığımızı da gösteriyor.
postgres=# \c myjhipsterplanet
You are now connected to database "myjhipsterplanet" as user "mypostgresqldumpplanet".
Örnek
Şöyle yaparız.
Beliritlen dosyayı çalıştırır. Şöyle yaparız.
\x seçeneği
\connect springbootjpa
Örnek
Şöyle yaparız
> \c pg_dev
> CREATE TABLE mini_ticker (...);
\copy
Örnek
Şöyle yaparız
psql -h "$host" -U postgres -d demo
-c "\copy (SELECT row_to_json(t) FROM ( $query ) t) To STDOUT"
>> metrics/query-output.log
Örnek
Şöyle yaparız. admission tablosuna csv dosyasındaki satırları kopyalar
\copy admission FROM '/home/data/admit_1.csv' DELIMITER ',' CSV HEADER
\d [table] seçeneği - Describe a table structure
Describe anlamına gelir. Tablonun sütunlarını gösterir.
Örnek
Şöyle yaparız
> CREATE TABLE grades(id SERIAL NOT NULL, g INT NOT NULL);
> CREATE INDEX grades_index ON grades(g);
> \d grades;
Table "public.grades"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+------------------------------------
id | integer | | not null | nextval('grades_id_seq'::regclass)
g | integer | | not null |
Indexes:
"grades_index" btree (g)
Örnek
Şöyle yaparız
demodb=# \dt
List of relations
Schema | Name | Type | Owner
--------+-----------------------+-------+----------
public | flyway_schema_history | table | postgres
public | tenant | table | postgres
(2 rows)
demodb=# \d tenant
Table "public.tenant"
Column | Type | Collation | Nullable | Default
--------+------------------------+-----------+----------+---------
id | uuid | | not null |
name | character varying(100) | | not null |
Indexes:
"tenant_pkey" PRIMARY KEY, btree (id)
\df - List functions
Örnek ver
\di seçeneği
Describe Index anlamına gelir. İndeksleri gösterir
Örnek
Şöyle yaparız
# \di+
List of relations
Schema | Name | Type | Owner | Table | Persistence | Access method | Size | Description
--------+-------+-------+----------+-------+-------------+---------------+---------+-------------
public | a_idx | index | postgres | t1 | permanent | btree | 6712 kB |
(1 row)
Sonra şöyle yaparız. Böylece index dosyasının ismini öğreniriz.
# select pg_relation_filepath('a_idx');
pg_relation_filepath
----------------------
base/16699/16723
(1 row)
Sonra şöyle yaparız. Böylece verinin saklandığı dizinin yolunu öğreniriz.
# show data_directory;
data_directory
-----------------------------------
/home/postgres/pgdata/data
(1 row)
Yani index dosyası burada /home/postgres/pgdata/data/base/16699/16723
Teyit etmek için şöyle yaparız.
# \! ls /home/postgres/pgdata/data/base/16699/16723
/home/postgres/pgdata/data/base/16699/16723
\dn - List schemas
Örnek ver
\dt seçeneği - List tables in the current database
Describe Tables anlamına gelir. Tabloları gösterir
Örnek
Şöyle yaparız
adv=> \dt
List of relations
Schema | Name | Type | Owner
--------+--------------------------------+-------+-------
adv | cfr_history_log | table | adv
...
\du seçeneği - List users and their roles
Describe Users anlamına gelir. Kullanıcıları gösterir
\dx seçeneği - List extensions
Örnek
Şöyle yaparız
partitioning_test=# \dxList of installed extensionsName | Version | Schema | Description--------------------+---------+------------+------------------------------------------------------------------------bloom | 1.0 | public | bloom access method - signature file based indexcitext | 1.6 | public | data type for case-insensitive character stringscitus | 13.1-1 | pg_catalog | Citus distributed databasecitus_columnar | 12.2-1 | pg_catalog | Citus Columnar extensionhstore | 1.8 | public | data type for storing sets of (key, value) pairspg_cron | 1.6 | pg_catalog | Job scheduler for PostgreSQLpg_ivm | 1.11 | pg_catalog | incremental view maintenance on PostgreSQLpg_partman | 5.2.4 | partman | Extension to manage partitioned tables by time or IDpg_stat_statements | 1.11 | public | track planning and execution statistics of all SQL statements executedpg_trgm | 1.6 | public | text similarity measurement and index searching based on trigramspgcrypto | 1.3 | public | cryptographic functionsplpgsql | 1.0 | pg_catalog | PL/pgSQL procedural languagepostgres_fdw | 1.1 | public | foreign-data wrapper for remote PostgreSQL serversuuid-ossp | 1.1 | public | generate universally unique identifiers (UUIDs)vector | 0.8.0 | public | vector data type and ivfflat and hnsw access methods(15 rows)
\i seçeneği
\i "C:\Users\myname\some path\query.sql"
\l seçeneği veya \list - List all databases
Veri tabanlarını listeler
Örnek
Şöyle yaparız. Burada 5 tane veri tabanı var.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------------------+------------------------+----------+------------+------------+---------------------------------------------------
myjhipsterplanet | myjhipsterplanet | UTF8 | en_US.utf8 | en_US.utf8 |
mypostgresqldumpplanet | mypostgresqldumpplanet | UTF8 | en_US.utf8 | en_US.utf8 |
postgres | mypostgresqldumpplanet | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | mypostgresqldumpplanet | UTF8 | en_US.utf8 | en_US.utf8 | =c/mypostgresqldumpplanet +
| | | | | mypostgresqldumpplanet=CTc/mypostgresqldumpplanet
template1 | mypostgresqldumpplanet | UTF8 | en_US.utf8 | en_US.utf8 | =c/mypostgresqldumpplanet +
| | | | | mypostgresqldumpplanet=CTc/mypostgresqldumpplanet
Select cümlesi ile gösterilen kayıtları expanded display olarak gösterir. Yani sütunları alt alta yazar
Hiç yorum yok:
Yorum Gönder