Tüm veri tabanı isimleri bu tablodadır
Örnek
Şöyle yaparız
SELECT datname FROM pg_database WHERE datname LIKE '${inpDBPattern}' ORDER BY 1 OFFSET ${inpOffset} LIMIT ${inpLimit}
SELECT datname FROM pg_database WHERE datname LIKE '${inpDBPattern}' ORDER BY 1 OFFSET ${inpOffset} LIMIT ${inpLimit}
... you can use the pg_stat_database view to retrieve information on database-level activity, such as the number of connections, transactions, and queries per second
SELECT pg_stat_reset();
SELECT name, settingFROM pg_settings WHERE name = ‘effective_io_concurrency’;
SELECTname,setting,category,short_descFROM pg_settingsWHERE name LIKE '%autovacuum%'
SELECT name, setting, boot_val FROM pg_settings WHERE name LIKE "autovacuum%";
SELECT checkpoints_timed, checkpoints_req, buffers_checkpoint, buffers_clean, maxwritten_clean, buffers_backend, buffers_allocFROM pg_stat_bgwriter;
This query returns a single row with several columns that provide information about the background writer process. The columns show the number of checkpoints that have been performed, the number of buffers written during checkpoints, the number of buffers cleaned by the background writer, the maximum number of buffers written in a single clean pass, and the number of buffers allocated and used by backends.
SELECT relname, heap_blks_read, heap_blks_hit, idx_blks_read, idx_blks_hitFROM pg_statio_user_tables;
This query returns a row for each table in the database, with columns for the number of blocks read and hit for both the table and its indexes. A high ratio of “hit” to “read” indicates that data is being retrieved from the cache, which is typically a good sign of good performance.
To perform case-insensitive queries, use ILIKE, regular expressions, or the lower() function on both sides of the comparison operator. If lower() is used frequently, the column should be indexed using the case_insensitive collation since otherwise, the index will not be used.
When the Lower function is used, the indexes on the relevant column become unusable. Each search will be done as a “sequential scan.” This will cause performance problems as the number of rows increases. “Expressional Index” is recommended as a solution. For details, see https://www.postgresql.org/docs/9.1/indexes-expressional.html.
For example, a common way to do case-insensitive comparisons is to use the lower function:SELECT * FROM test1 WHERE lower(col1) = 'value';This query can use an index if one has been defined on the result of the lower(col1) function:CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));If we were to declare this index UNIQUE, it would prevent creation of rows whose col1 values differ only in case, as well as rows whose col1 values are actually identical. Thus, indexes on expressions can be used to enforce constraints that are not definable as simple unique constraints.
If lower() is used frequently, the column should be indexed using the case_insensitive collation since otherwise, the index will not be used.
/*See https://www.postgresql.org/docs/current/collation.html#COLLATION-NONDETERMINISTIC */
CREATE COLLATION case_insensitive
(provider = icu, locale='und-u-ks-level2', deterministic=false);
CREATE UNIQUE INDEX users_email_unique ON users(email COLLATE case_insensitive);
EXPLAIN
SELECT * FROM users
WHERE lower(email) = lower('Seed-system-user')
AND deleted_at IS NULL;
-> Bitmap Index Scan on users_email_unique
SELECT * FROM test1 WHERE lower(col1) = lower('value');
.. a Bitmap Heap Scan always works in tandem with Bitmap Index Scan to speed things up.
Bitmap Index Scan scans the index first to create a bitmap of which pages need to be fetched, and Bitmap Heap Scan then uses the bitmap to fetch the data from the pages.
.... index scans cause random I/O if there is no ordering to the rows (name is text content). This is costly in rotational hard drives. To solve this, the Planner takes a two-stage approach. The Bitmap Index Scan constructs a data structure called a bitmap from the index present and represents the approximate location of pages in the disk and feeds it to the parent node, i.e., Bitmap Heap Scan, which then uses that to fetch the pages/rows.
CREATE INDEX name_str_idx ON fake_data USING BTREE(name);
EXPLAIN ANALYZE SELECT * FROM fake_data WHERE
fake_data.name = 'David';
CREATE INDEX idx weather_type ON weather(event_type);
Bitmap Heap Scan on weather (cost=4.36..37.56 rows=11 width=622) (actual time=0.500..2.300 rows=11 loops=1)
Recheck Cond: ((event type)::text = 'Winter Storm'::text)
Heap Blocks: exact=6
-> Bitmap Index Scan on idx weather type (cost=0.00..4.36 rows=11] width =0) (actual time=0.400..0.400 rows=11 loops=1)
Index Cond: ((event type)::text = 'Winter Storm'::text)
Planning Time: 23.300 ms
Execution Time: 7.200 ms
(7 rows)
EXPLAIN ANALYZE SELECT * FROM fake_data WHERE
fake_data.id = 1000 OR fake_data.name = 'David';
EXPLAIN ANALYZE SELECT * FROM fake_data WHERE
fake_data.id <= 1000 OR fake_data.name = 'David';
Sequential Scans are the slowest of all the plans we have seen so far because there is nothing to optimize there. The Planner goes over the data sequentially and tries to find the result. PostgreSQL optimizes this further by adding parallelism in the queries.
EXPLAIN ANALYZE SELECT count(*)FROM orders AS oJOIN order_items as oiON o.order_id = oi.order_item_order_idWHERE o.order_customer_id = 5;
|QUERY PLAN | |-------------------------------------------------------------------------------------------------------------------------------------------------------------------| |Aggregate (cost=53.71..53.72 rows=1 width=8) (actual time=2.434..2.435 rows=1 loops=1) | | -> Nested Loop (cost=4.76..53.67 rows=15 width=0) (actual time=1.872..2.428 rows=7 loops=1) | | -> Bitmap Heap Scan on orders o (cost=4.34..26.49 rows=6 width=4) (actual time=1.034..1.315 rows=4 loops=1) | | Recheck Cond: (order_customer_id = 5) | | Heap Blocks: exact=4 | | -> Bitmap Index Scan on orders_order_customer_id_idx (cost=0.00..4.34 rows=6 width=0) (actual time=0.696..0.696 rows=4 loops=1) | | Index Cond: (order_customer_id = 5) | | -> Index Only Scan using order_items_order_item_order_id_idx on order_items oi (cost=0.42..4.49 rows=4 width=4) (actual time=0.275..0.276 rows=2 loops=4)| | Index Cond: (order_item_order_id = o.order_id) | | Heap Fetches: 0 | |Planning Time: 5.706 ms | |Execution Time: 2.565 ms
EXPLAIN SELECT o.*, round(sum(oi.order_item_subtotal)::numeric, 2) as revenue FROM orders as o JOIN order_items as oi ON o.order_id = oi.order_item_order_id WHERE o.order_id = 2 GROUP BY o.order_id, o.order_date, o.order_customer_id, o.order_status;
|order_id|order_date |order_customer_id|order_status |revenue| |--------|-----------------------|-----------------|---------------|-------| |2 |2013-07-25 00:00:00.000|256 |PENDING_PAYMENT|579.98 |
|QUERY PLAN | |---------------------------------------------------------------------------------------| |GroupAggregate (cost=0.29..3427.86 rows=1 width=58) | | Group Key: o.order_id | | -> Nested Loop (cost=0.29..3427.82 rows=4 width=34) | | -> Index Scan using orders_pkey on orders o (cost=0.29..8.31 rows=1 width=26)| | Index Cond: (order_id = 2) | | -> Seq Scan on order_items oi (cost=0.00..3419.47 rows=4 width=12) | | Filter: (order_item_order_id = 2)
restartUbuntu/Debian packages for Postgres have their own layer on top of initdb and pg_ctl to control multiple instances and the integration with systemd.
pg_ctl -D /pgsql/data/replica/ restart