Made larger DB setup script

This commit is contained in:
Bill
2025-11-17 15:42:25 -07:00
parent 8db32ceb5b
commit da34dbda07

View File

@@ -4,7 +4,7 @@ DROP TABLE IF EXISTS benchmark_table;
-- 2. Create the new 10-column table -- 2. Create the new 10-column table
CREATE TABLE benchmark_table ( CREATE TABLE benchmark_table (
id BIGINT, id BIGINT,
uuid TEXT, -- Storing as TEXT for simplicity, can be native UUID uuid TEXT,
username TEXT, username TEXT,
score REAL, score REAL,
is_active BOOLEAN, is_active BOOLEAN,
@@ -15,113 +15,82 @@ CREATE TABLE benchmark_table (
rating FLOAT8 rating FLOAT8
); );
-- 3. Use COPY FROM STDIN to bulk-load 100 rows of data -- 3. Use generate_series to insert 1,000,000 rows of data
-- This is the fastest way to insert data into Postgres. INSERT INTO benchmark_table (
COPY benchmark_table (id, uuid, username, score, is_active, last_login, notes, course_id, start_date, rating) FROM STDIN WITH (FORMAT csv); id,
1,a1b2c3d4-e5f6-7890-1234-567890abcdef,user_1,95.5,true,2025-01-10 10:30:00,First note,101,2024-01-01,4.5 uuid,
2,b2c3d4e5-f6a7-8901-2345-678901bcdef0,user_2,88.0,true,2025-02-15 11:45:10,Second note,102,2024-01-02,4.2 username,
3,c3d4e5f6-a7b8-9012-3456-789012cdef01,user_3,72.1,false,2025-03-20 12:00:05,,101,2024-01-03,3.8 score,
4,d4e5f6a7-b8c9-0123-4567-890123def012,user_4,99.9,true,2025-04-25 14:15:30,High score,103,2024-01-04,4.9 is_active,
5,e5f6a7b8-c9d0-1234-5678-901234ef0123,user_5,65.0,false,2025-05-30 09:10:20,Needs review,102,2024-01-05,3.1 last_login,
6,f6a7b8c9-d0e1-2345-6789-012345f01234,user_6,78.5,true,2025-06-01 18:05:00,Passed,101,2024-01-06,4.0 notes,
7,a7b8c9d0-e1f2-3456-7890-123456012345,user_7,82.3,true,2025-07-07 13:20:45,,104,2024-01-07,4.1 course_id,
8,b8c9d0e1-f2a3-4567-8901-234567123456,user_8,91.0,true,2025-08-12 10:00:00,Excellent,103,2024-01-08,4.7 start_date,
9,c9d0e1f2-a3b4-5678-9012-345678234567,user_9,55.0,false,2025-09-18 20:30:15,Failed,102,2024-01-09,2.5 rating
10,d0e1f2a3-b4c5-6789-0123-456789345678,user_10,89.5,true,2025-10-22 11:11:11,Good work,101,2024-01-10,4.6 )
11,e1f2a3b4-c5d6-7890-1234-567890456789,user_11,92.0,true,2025-11-28 14:55:00,Solid,103,2024-01-11,4.8 SELECT
12,f2a3b4c5-d6e7-8901-2345-678901567890,user_12,75.0,true,2025-12-01 08:30:00,,104,2024-01-12,3.9 i AS id,
13,a3b4c5d6-e7f8-9012-3456-789012678901,user_13,68.2,false,2025-01-15 17:45:30,Re-test,102,2024-01-13,3.3 md5(i::TEXT) AS uuid, -- Use md5 to generate a text uuid
14,b4c5d6e7-f8a9-0123-4567-890123789012,user_14,81.0,true,2025-02-20 12:01:00,Passed,101,2024-01-14,4.3 'user_' || i AS username,
15,c5d6e7f8-a9b0-1234-5678-901234890123,user_15,77.7,true,2025-03-25 10:10:10,Average,103,2024-01-15,3.7 (random() * 100)::REAL AS score,
16,d6e7f8a9-b0c1-2345-6789-012345901234,user_16,94.5,true,2025-04-30 16:20:25,,104,2024-01-16,4.8 (i % 2 = 0) AS is_active,
17,e7f8a9b0-c1d2-3456-7890-123456012345,user_17,83.0,true,2025-05-05 11:30:00,Good,101,2024-01-17,4.2 NOW() - (random() * '365 days'::INTERVAL) AS last_login,
18,f8a9b0c1-d2e3-4567-8901-234567123456,user_18,60.5,false,2025-06-10 19:00:50,Needs help,102,2024-01-18,2.9 CASE WHEN i % 10 = 0 THEN NULL ELSE 'Sample notes' END AS notes,
19,a9b0c1d2-e3f4-5678-9012-345678234567,user_19,88.5,true,2025-07-15 14:45:00,Great,103,2024-01-19,4.6 (random() * 10 + 100)::INT AS course_id,
20,b0c1d2e3-f4a5-6789-0123-456789345678,user_20,90.0,true,2025-08-20 09:00:00,,104,2024-01-20,4.7 (NOW() - (random() * '1000 days'::INTERVAL))::DATE AS start_date,
21,c1d2e3f4-a5b6-7890-1234-567890456789,user_21,93.2,true,2025-09-25 10:30:00,Top score,101,2024-01-21,4.9 (random() * 5)::FLOAT8 AS rating
22,d2e3f4a5-b6c7-8901-2345-678901567890,user_22,76.8,true,2025-10-30 11:45:10,Passed,102,2024-01-22,3.9 FROM generate_series(1, 1000000) s(i);
23,e3f4a5b6-c7d8-9012-3456-789012678901,user_23,69.9,false,2025-11-04 12:00:05,,101,2024-01-23,3.5
24,f4a5b6c7-d8e9-0123-4567-890123789012,user_24,85.0,true,2025-12-10 14:15:30,Good,103,2024-01-24,4.4 -- 4. Analyze the table for better query planning (good practice)
25,a5b6c7d8-e9f0-1234-5678-901234890123,user_25,70.0,true,2025-01-15 09:10:20,Review,102,2024-01-25,3.6 ANALYZE benchmark_table;
26,b6c7d8e9-f0a1-2345-6789-012345901234,user_26,81.5,true,2025-02-20 18:05:00,Passed,101,2024-01-26,4.1 ```
27,c7d8e9f0-a1b2-3456-7890-123456012345,user_27,87.3,true,2025-03-27 13:20:45,,104,2024-01-27,4.5
28,d8e9f0a1-b2c3-4567-8901-234567123456,user_28,94.0,true,2025-04-01 10:00:00,Excellent,103,2024-01-28,4.8 ### Action 2: Commit and Push the Change
29,e9f0a1b2-c3d4-5678-9012-345678234567,user_29,58.0,false,2025-05-07 20:30:15,Failed,102,2024-01-29,2.8
30,f0a1b2c3-d4e5-6789-0123-456789345678,user_30,90.5,true,2025-06-12 11:11:11,Great work,101,2024-01-30,4.7 You must commit and push this new `setup_db.sql` to your GitHub repo so Colab can pull it.
31,0a1b2c3d-4e5f-6789-0123-456789abcdef,user_31,96.0,true,2025-07-18 14:55:00,Top,103,2024-01-31,4.9
32,1b2c3d4e-5f6a-7890-1234-567890bcdef0,user_32,74.0,true,2025-08-23 08:30:00,,104,2024-02-01,3.8 ```bash
33,2c3d4e5f-6a7b-8901-2345-678901cdef01,user_33,67.0,false,2025-09-28 17:45:30,Re-test,102,2024-02-02,3.2 # In your local terminal
34,3d4e5f6a-7b8c-9012-3456-789012def012,user_34,80.0,true,2025-10-03 12:01:00,Passed,101,2024-02-03,4.2 git add setup_db.sql
35,4e5f6a7b-8c9d-0123-4567-890123ef0123,user_35,79.0,true,2025-11-08 10:10:10,Average,103,2024-02-04,3.8 git commit -m "Create 1M row benchmark table"
36,5f6a7b8c-9d0e-1234-5678-901234f01234,user_36,95.0,true,2025-12-14 16:20:25,,104,2024-02-05,4.9 git push
37,6a7b8c9d-0e1f-2345-6789-012345012345,user_37,84.5,true,2025-01-20 11:30:00,Good,101,2024-02-06,4.3 ```
38,7b8c9d0e-1f2a-3456-7890-123456123456,user_38,62.0,false,2025-02-25 19:00:50,Needs help,102,2024-02-07,3.0
39,8c9d0e1f-2a3b-4567-8901-234567234567,user_39,87.0,true,2025-03-02 14:45:00,Great,103,2024-02-08,4.5 ### Action 3: Update Your Colab Notebook
40,9d0e1f2a-3b4c-5678-9012-345678345678,user_40,91.8,true,2025-04-07 09:00:00,,104,2024-02-09,4.7
41,0e1f2a3b-4c5d-6789-0123-456789456789,user_41,94.2,true,2025-05-13 10:30:00,Top score,101,2024-02-10,4.8 Now, in Colab, **replace your old Cell 2 and Cell 3** with these two new cells.
42,1f2a3b4c-5d6e-7890-1234-567890567890,user_42,78.0,true,2025-06-18 11:45:10,Passed,102,2024-02-11,4.0
43,2a3b4c5d-6e7f-8901-2345-678901678901,user_43,71.5,false,2025-07-24 12:00:05,,101,2024-02-12,3.6 **New Cell 2 (Install & Setup):** This cell now does *all* setup in one go to fix the connection error.
44,3b4c5d6e-7f8a-9012-3456-789012789012,user_44,86.3,true,2025-08-29 14:15:30,Good,103,2024-02-13,4.5
45,4c5d6e7f-8a9b-0123-4567-890123890123,user_45,72.0,true,2025-09-03 09:10:20,Review,102,2024-02-14,3.7 ```python
46,5d6e7f8a-9b0c-1234-5678-901234901234,user_46,83.0,true,2025-10-09 18:05:00,Passed,101,2024-02-15,4.2 # 2. Install Rust, Tools, and Clone Repo
47,6e7f8a9b-0c1d-2345-6789-012345012345,user_47,89.0,true,2025-11-14 13:20:45,,104,2024-02-16,4.6 !curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
48,7f8a9b0c-1d2e-3456-7890-123456123456,user_48,96.5,true,2025-12-20 10:00:00,Excellent,103,2024-02-17,4.9 import os
49,8a9b0c1d-2e3f-4567-8901-234567234567,user_49,60.0,false,2025-01-25 20:30:15,Failed,102,2024-02-18,2.9 os.environ['PATH'] += ":/root/.cargo/bin"
50,9b0c1d2e-3f4a-5678-9012-345678345678,user_50,92.5,true,2025-02-01 11:11:11,Great work,101,2024-02-19,4.8 !pip install maturin wheel
51,a1b2c3d4-e5f6-7890-1234-567890abcdef,user_51,95.5,true,2025-01-10 10:30:00,First note,101,2024-01-01,4.5
52,b2c3d4e5-f6a7-8901-2345-678901bcdef0,user_52,88.0,true,2025-02-15 11:45:10,Second note,102,2024-01-02,4.2 # Go to root, clean up, and clone fresh
53,c3d4e5f6-a7b8-9012-3456-789012cdef01,user_53,72.1,false,2025-03-20 12:00:05,,101,2024-01-03,3.8 %cd /content/
54,d4e5f6a7-b8c9-0123-4567-890123def012,user_54,99.9,true,2025-04-25 14:15:30,High score,103,2024-01-04,4.9 !rm -rf unchecked-io
55,e5f6a7b8-c9d0-1234-5678-901234ef0123,user_55,65.0,false,2025-05-30 09:10:20,Needs review,102,2024-01-05,3.1 !git clone https://github.com/BillTheMaker/unchecked-io.git
56,f6a7b8c9-d0e1-2345-6789-012345f01234,user_56,78.5,true,2025-06-01 18:05:00,Passed,101,2024-01-06,4.0 %cd unchecked-io
57,a7b8c9d0-e1f2-3456-7890-123456012345,user_57,82.3,true,2025-07-07 13:20:45,,104,2024-01-07,4.1
58,b8c9d0e1-f2a3-4567-8901-234567123456,user_58,91.0,true,2025-08-12 10:00:00,Excellent,103,2024-01-08,4.7 # Build and install UncheckedIO
59,c9d0e1f2-a3b4-5678-9012-345678234567,user_59,55.0,false,2025-09-18 20:30:15,Failed,102,2024-01-09,2.5 !pip install .
60,d0e1f2a3-b4c5-6789-0123-456789345678,user_60,89.5,true,2025-10-22 11:11:11,Good work,101,2024-01-10,4.6 ```
61,e1f2a3b4-c5d6-7890-1234-567890456789,user_61,92.0,true,2025-11-28 14:55:00,Solid,103,2024-01-11,4.8
62,f2a3b4c5-d6e7-8901-2345-678901567890,user_62,75.0,true,2025-12-01 08:30:00,,104,2024-01-12,3.9 **New Cell 3 (Start & Populate DB):** This cell installs Postgres, robustly starts it, and runs your *new* 1M row script.
63,a3b4c5d6-e7f8-9012-3456-789012678901,user_63,68.2,false,2025-01-15 17:45:30,Re-test,102,2024-01-13,3.3
64,b4c5d6e7-f8a9-0123-4567-890123789012,user_64,81.0,true,2025-02-20 12:01:00,Passed,101,2024-01-14,4.3 ```python
65,c5d6e7f8-a9b0-1234-5678-901234890123,user_65,77.7,true,2025-03-25 10:10:10,Average,103,2024-01-15,3.7 # 3. Install, Run, and Populate PostgreSQL Server
66,d6e7f8a9-b0c1-2345-6789-012345901234,user_66,94.5,true,2025-04-30 16:20:25,,104,2024-01-16,4.8 print("Installing PostgreSQL...")
67,e7f8a9b0-c1d2-3456-7890-123456012345,user_67,83.0,true,2025-05-05 11:30:00,Good,101,2024-01-12,4.2 !apt-get -y -qq install postgresql postgresql-client > /dev/null
68,f8a9b0c1-d2e3-4567-8901-234567123456,user_68,60.5,false,2025-06-10 19:00:50,Needs help,102,2024-01-18,2.9
69,a9b0c1d2-e3f4-5678-9012-345678234567,user_69,88.5,true,2025-07-15 14:45:00,Great,103,2024-01-19,4.6 # Force the service to start and set password
70,b0c1d2e3-f4a5-6789-0123-456789345678,user_70,90.0,true,2025-08-20 09:00:00,,104,2024-01-20,4.7 !service postgresql start
71,c1d2e3f4-a5b6-7890-1234-567890456789,user_71,93.2,true,2025-09-25 10:30:00,Top score,101,2024-01-21,4.9 !sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'mysecretpassword';"
72,d2e3f4a5-b6c7-8901-2345-678901567890,user_72,76.8,true,2025-10-30 11:45:10,Passed,102,2024-01-22,3.9
73,e3f4a5b6-c7d8-9012-3456-789012678901,user_73,69.9,false,2025-11-04 12:00:05,,101,2024-01-23,3.5 print("Running 1M row setup_db.sql script (this may take a moment)...")
74,f4a5b6c7-d8e9-0123-4567-890123789012,user_74,85.0,true,2025-12-10 14:15:30,Good,103,2024-01-24,4.4 # Run our *new* 1M row SQL script
75,a5b6c7d8-e9f0-1234-5678-901234890123,user_75,70.0,true,2025-01-15 09:10:20,Review,102,2024-01-25,3.6 !psql "postgresql://postgres:mysecretpassword@localhost:5432/postgres" -f setup_db.sql
76,b6c7d8e9-f0a1-2345-6789-012345901234,user_76,81.5,true,2025-02-20 18:05:00,Passed,101,2024-01-26,4.1 print("Database setup complete.")
77,c7d8e9f0-a1b2-3456-7890-123456012345,user_77,87.3,true,2025-03-27 13:20:45,,104,2024-01-27,4.5
78,d8e9f0a1-b2c3-4567-8901-234567123456,user_78,94.0,true,2025-04-01 10:00:00,Excellent,103,2024-01-28,4.8
79,e9f0a1b2-c3d4-5678-9012-345678234567,user_79,58.0,false,2025-05-07 20:30:15,Failed,102,2024-01-29,2.8
80,f0a1b2c3-d4e5-6789-0123-456789345678,user_80,90.5,true,2025-06-12 11:11:11,Great work,101,2024-01-30,4.7
81,0a1b2c3d-4e5f-6789-0123-456789abcdef,user_81,96.0,true,2025-07-18 14:55:00,Top,103,2024-01-31,4.9
82,1b2c3d4e-5f6a-7890-1234-567890bcdef0,user_82,74.0,true,2025-08-23 08:30:00,,104,2024-02-01,3.8
83,2c3d4e5f-6a7b-8901-2345-678901cdef01,user_83,67.0,false,2025-09-28 17:45:30,Re-test,102,2024-02-02,3.2
84,3d4e5f6a-7b8c-9012-3456-789012def012,user_84,80.0,true,2025-10-03 12:01:00,Passed,101,2024-02-03,4.2
85,4e5f6a7b-8c9d-0123-4567-890123ef0123,user_85,79.0,true,2025-11-08 10:10:10,Average,103,2024-02-04,3.8
86,5f6a7b8c-9d0e-1234-5678-901234f01234,user_86,95.0,true,2025-12-14 16:20:25,,104,2024-02-05,4.9
87,6a7b8c9d-0e1f-2345-6789-012345012345,user_87,84.5,true,2025-01-20 11:30:00,Good,101,2024-02-06,4.3
88,7b8c9d0e-1f2a-3456-7890-123456123456,user_88,62.0,false,2025-02-25 19:00:50,Needs help,102,2024-02-07,3.0
89,8c9d0e1f-2a3b-4567-8901-234567234567,user_89,87.0,true,2025-03-02 14:45:00,Great,103,2024-02-08,4.5
90,9d0e1f2a-3b4c-5678-9012-345678345678,user_90,91.8,true,2025-04-07 09:00:00,,104,2024-02-09,4.7
91,0e1f2a3b-4c5d-6789-0123-456789456789,user_91,94.2,true,2025-05-13 10:30:00,Top score,101,2024-02-10,4.8
92,1f2a3b4c-5d6e-7890-1234-567890567890,user_92,78.0,true,2025-06-18 11:45:10,Passed,102,2024-02-11,4.0
93,2a3b4c5d-6e7f-8901-2345-678901678901,user_93,71.5,false,2025-07-24 12:00:05,,101,2024-02-12,3.6
94,3b4c5d6e-7f8a-9012-3456-789012789012,user_94,86.3,true,2025-08-29 14:15:30,Good,103,2024-02-13,4.5
95,4c5d6e7f-8a9b-0123-4567-890123890123,user_95,72.0,true,2025-09-03 09:10:20,Review,102,2024-02-14,3.7
96,5d6e7f8a-9b0c-1234-5678-901234901234,user_96,83.0,true,2025-10-09 18:05:00,Passed,101,2024-02-15,4.2
97,6e7f8a9b-0c1d-2345-6789-012345012345,user_97,89.0,true,2025-11-14 13:20:45,,104,2024-02-16,4.6
98,7f8a9b0c-1d2e-3456-7890-123456123456,user_98,96.5,true,2025-12-20 10:00:00,Excellent,103,2024-02-17,4.9
99,8a9b0c1d-2e3f-4567-8901-234567234567,user_99,60.0,false,2025-01-25 20:30:15,Failed,102,2024-02-18,2.9
100,9b0c1d2e-3f4a-5678-9012-345678345678,user_100,92.5,true,2025-02-01 11:11:11,Great work,101,2024-02-19,4.8
\.
-- ```
-- **To run this script:**
-- 1. Save it as `setup_db.sql`.
-- 2. Use the `psql` command-line tool (which comes with Postgres) to execute it against your database (the one running in Docker):
-- ```bash
-- psql "postgresql://postgres:mysecretpassword@localhost:5433/postgres" -f setup_db.sql