Last active
September 27, 2025 08:41
-
-
Save up1/406f1698847f2dc1fd3776ddf02ea0ea to your computer and use it in GitHub Desktop.
PostgreSQL 18 with async read
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ตรวจสอบ version | |
| SELECT version(); | |
| PostgreSQL 18.0 (Debian 18.0-1.pgdg13+3) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 14.2.0-19) 14.2.0, 64-bit | |
| # ดูการ config | |
| SELECT name, setting, context, short_desc | |
| FROM pg_settings | |
| WHERE name LIKE 'io_%' | |
| ORDER BY name; | |
| io_combine_limit | 32 | user | Limit on the size of data reads and writes. | |
| io_max_combine_limit | 128 | postmaster | Server-wide limit that clamps io_combine_limit. | |
| io_max_concurrency | 64 | postmaster | Max number of IOs that one process can execute simultaneously. | |
| io_method | worker | postmaster | Selects the method for executing asynchronous I/O. | |
| io_workers | 6 | sighup | Number of IO worker processes, for io_method=worker. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For worker method :: Background I/O Workers | |
| ALTER SYSTEM SET io_method = 'worker'; | |
| ALTER SYSTEM SET io_workers = 4; | |
| # For io_uring method (Linux only, requires liburing) | |
| ALTER SYSTEM SET io_method = 'io_uring'; | |
| # For sync method (traditional behavior) | |
| ALTER SYSTEM SET io_method = 'sync'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE EXTENSION IF NOT EXISTS pg_prewarm; | |
| CREATE TABLE async_io_test ( | |
| id SERIAL PRIMARY KEY, | |
| data TEXT, | |
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, | |
| random_num INTEGER, | |
| filler TEXT DEFAULT repeat('x', 100) | |
| ); | |
| INSERT INTO async_io_test (data, random_num) | |
| SELECT | |
| 'Performance test data for async I/O - row ' || i, | |
| (random() * 1000000)::INTEGER | |
| FROM generate_series(1, 500000) AS i; | |
| CREATE INDEX idx_async_io_random ON async_io_test(random_num); | |
| CREATE INDEX idx_async_io_created ON async_io_test(created_at); | |
| CREATE INDEX idx_async_io_text ON async_io_test USING gin(to_tsvector('english', data)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT pg_stat_reset(); | |
| SELECT pg_prewarm('async_io_test'::regclass, 'buffer', 'main', NULL, NULL); | |
| EXPLAIN (ANALYZE, BUFFERS, VERBOSE) | |
| SELECT COUNT(*) | |
| FROM async_io_test | |
| WHERE data LIKE '%500000%'; | |
| EXPLAIN (ANALYZE, BUFFERS, VERBOSE) | |
| SELECT id, data, random_num | |
| FROM async_io_test | |
| WHERE random_num BETWEEN 100000 AND 200000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment