frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Pgtestdb's template cloning approach to testing is fast

https://brandur.org/fragments/pgtestdb
23•brandur•1h ago

Comments

hugodutka•1h ago
Cloning a template is IO-heavy. You can speed it up further by putting postgres on a ramdisk.
ltbarcly3•53m ago
Just turning off fsync is basically just as fast as a ramdisk and you can't use up all your memory with one big test.
koolba•25m ago
Turning off synchronous_commit gets you most of the way without ever worrying about data corruption if something crashes mid way through.

https://www.postgresql.org/docs/current/wal-async-commit.htm...

ltbarcly3•54m ago
Our db clearing takes like 5ms (large schema from mature company, not a toy). We start by restoring a production schema dump which ensures our test db / devdb schema is basically identical to what we run in production. Any migrations you are working on in your branch get added to the restore of the prod schema after it runs. Building a schema from ORM definitions is what you do if you don't care about your life or time. Clearing the test db takes something similar. This is fine, using template db's is a good way to make a scratch copy of a local database to test migrations (rsync is better if you are technical enough to use it to restore after destructive changes).

Timings:

  - create testdb: 9ms
  - restore prod schema: 500ms (done once per test process)
  - clear test data in 96 tables between tests that write to db (5ms)
The fastest way to clear a test db is to run a query to get every schema/table name, then run ";".join("`DELETE FROM {schema}.{tablename};" for schema, table in my_tables) after putting the db in replica mode. This takes single digit ms a lot of the time even with a decent amount of test data. I've done it every which way and this is by far the fastest way to clear data between tests.

    -- This will work on basically any postgresql database with basically any schema so just use it.
    test_db_2235191=# CREATE OR REPLACE PROCEDURE public.delete_all_table_data()
        LANGUAGE plpgsql
        AS $procedure$
        DECLARE
            target record;
            previous_replication_role text;
        BEGIN
            previous_replication_role :=
                current_setting('session_replication_role');
        PERFORM set_config('session_replication_role', 'replica', true);

        BEGIN
            FOR target IN
                SELECT namespace.nspname AS schema_name,
                       relation.relname AS table_name
                FROM pg_catalog.pg_class AS relation
                JOIN pg_catalog.pg_namespace AS namespace
                  ON namespace.oid = relation.relnamespace
                WHERE relation.relkind = 'r'
                  AND namespace.nspname NOT LIKE 'pg\_%' ESCAPE '\'
                  AND namespace.nspname <> 'information_schema'
                ORDER BY namespace.nspname, relation.relname
            LOOP
                RAISE NOTICE 'Deleting %.%',
                    target.schema_name,
                    target.table_name;

                EXECUTE format(
                    'DELETE FROM %I.%I',
                    target.schema_name,
                    target.table_name
                );
            END LOOP;
        EXCEPTION
            WHEN OTHERS THEN
                PERFORM set_config(
                    'session_replication_role',
                    previous_replication_role,
                    true
                );
                RAISE;
        END;

        PERFORM set_config(
            'session_replication_role',
            previous_replication_role,
            true
        );
    END;
    $procedure$;
    CREATE PROCEDURE
    Time: 0.840 ms


    test_db_2235191=# CALL public.delete_all_table_data();
    NOTICE:  ... (notices removed for 96 tables)
    CALL
    Time: 5.855 ms

I ♥ RSS – A directory of people who love RSS

https://andrewshell.org/2026/07/i-%e2%99%a5-rss/
53•speckx•41m ago•30 comments

Cursor removed cost information from the usage page and CSV export

https://forum.cursor.com/t/usage-page-to-token-amount-what/167153
124•EugeneOZ•2h ago•50 comments

The Art of 64-bit Assembly

https://nostarch.com/art-64-bit-assembly-v2
90•0x54MUR41•3h ago•46 comments

Kaisel – Routes as Values. Dart 3 Native Router for Flutter

https://kaisel.dev/
14•TheWiggles•48m ago•0 comments

RipGrep musl binaries occasionally segfault during very-large searches

https://github.com/BurntSushi/ripgrep/issues/3494
180•throwaway2037•5h ago•101 comments

Explorative modeling: Train on the best of K guesses

https://alexiglad.github.io/blog/2026/explorative_modeling/
24•DSemba•2h ago•3 comments

Pgtestdb's template cloning approach to testing is fast

https://brandur.org/fragments/pgtestdb
23•brandur•1h ago•4 comments

A Surveillance Treaty in Disguise: Canada Signs UN Cybercrime Convention

https://www.michaelgeist.ca/2026/07/a-surveillance-treaty-in-disguise-the-trouble-with-canadas-qu...
150•iamnothere•3h ago•79 comments

Register deprivation: spills and runtime under forced register scarcity

https://rjp.io/blog/2026-07-19-register-deprivation
11•surprisetalk•2d ago•0 comments

Study uncovers lost 'golden age' of languages

https://news.yale.edu/2026/07/23/study-uncovers-lost-golden-age-languages
32•gmays•2d ago•19 comments

Charlie Stross – On the non-use of AI in my writing process

https://www.antipope.org/charlie/blog-static/2026/08/on-the-non-use-of-ai-in-my-wri.html
76•jwx48•4h ago•64 comments

Linux on ESP32

https://github.com/GrieferPig/esp32-s31-linux
44•boveyking•3d ago•15 comments

Manual: •.,:;?·

https://type.today/en/journal/dots
90•behnamoh•2d ago•18 comments

Rear center fuel tank adds roughly 20k liters and extends range by 1k NM

https://www.airbus.com/en/newsroom/press-releases/2026-06-worlds-longest-range-aircraft-the-airbu...
17•r2sk5t•4d ago•10 comments

Flint: A Visualization Language for the AI Era

https://microsoft.github.io/flint-chart/
224•vinhnx•14h ago•65 comments

Kontigo (YC S24) Is Hiring

https://www.ycombinator.com/companies/kontigo/jobs/xAo6tMt-founding-engineer
1•jecastillof•5h ago

qm – Multiplayer agent harness for work

https://github.com/yc-software/qm
632•tosh•23h ago•146 comments

Scope of Hacks on U.S. Water Supply Widens as Evidence Points to Iran

https://www.nytimes.com/2026/08/01/us/politics/iran-cyberattack-water-systems.html
53•jbegley•1h ago•39 comments

RamenHaus

https://ramen.haus/
169•oler•8h ago•83 comments

Solid Queue 1.6.0 now supports fiber workers

https://github.com/rails/solid_queue/releases/tag/v1.6.0
71•earcar•9h ago•28 comments

A tiny holdout building in the middle of Macy’s is back in view

https://ephemeralnewyork.wordpress.com/2026/07/27/hidden-by-billboards-for-over-100-years-the-tin...
154•donohoe•3d ago•43 comments

GitHub has alternatives, but no replacement

https://lalitm.com/post/github-alternatives/
67•lalitmaganti•1h ago•85 comments

Elevators

https://john.fun/elevators
1511•Jrh0203•1d ago•380 comments

How to Exist

https://www.raptitude.com/2026/07/how-to-exist/
321•walterbell•17h ago•189 comments

Software for One

https://www.ajwaxman.com/writing/software-for-one
199•awaxman11•3d ago•203 comments

Toast IDE Gets Markdown Spell Checking

https://github.com/paradise-runner/toast
3•dividedcomet•2h ago•0 comments

Run Kimi K3 using 29 GB of RAM at 0.50 tok/s

https://github.com/sqliteai/waste
304•marcobambini•1d ago•141 comments

Assessment of open AI math results

https://twitter.com/stalkermustang/status/2083485500250198453
6•paulpauper•26m ago•1 comments

The development pipeline is a production system

https://sundry.jerryorr.com/2026/07/31/development-pipeline-is-a-production-system
133•firefoxd•14h ago•66 comments

Astro Loop

https://pubdeer.com/
21•BaseBaal•5h ago•4 comments