Initial commit
This commit is contained in:
commit
51c8b33ca0
|
@ -0,0 +1,2 @@
|
|||
postgres/
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
# Milk Sad Lookup
|
||||
|
||||
Insert many rows of sha256 hashes into a Postgres database.
|
||||
|
||||
1. Install `postgress-client`:
|
||||
|
||||
```shell
|
||||
sudo apt install postgres-client
|
||||
```
|
||||
|
||||
2. Install Docker
|
||||
3. Install Python dependencies:
|
||||
|
||||
```shell
|
||||
pip install psycopg2
|
||||
```
|
||||
|
||||
4. Run the database via Docker:
|
||||
|
||||
```shell
|
||||
./mock/postgres.sh
|
||||
```
|
||||
|
||||
5. Configure the database:
|
||||
- Log into `psql shell`:
|
||||
|
||||
```shell
|
||||
psql -h localhost -p 5432 -U postgres
|
||||
```
|
||||
|
||||
Password: `test`
|
||||
|
||||
- Create Database, table, and index:
|
||||
|
||||
```shell
|
||||
postgres=# CREATE DATABASE hashes;
|
||||
postgres=# \c hashes;
|
||||
hashes=# CREATE TABLE hashes(id BYTEA);
|
||||
hashes=# CREATE INDEX hashes_id on hashes(id);
|
||||
```
|
||||
|
||||
6. Hammer time:
|
||||
|
||||
```shell
|
||||
./mock/insert_into.py
|
||||
```
|
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import uuid
|
||||
import hashlib
|
||||
import psycopg2
|
||||
|
||||
conn = psycopg2.connect("user=postgres password=test host=0.0.0.0 dbname=hashes")
|
||||
|
||||
RANGE = 4294967295
|
||||
|
||||
cur = conn.cursor()
|
||||
for entry in range(RANGE):
|
||||
hash = hashlib.sha256(str(uuid.uuid4()).encode()).digest()
|
||||
cur.execute("""INSERT INTO hashes(id) VALUES(%s);""", (hash, ))
|
||||
if entry % 100000 == 0: # Print progress every 100,000 commits
|
||||
conn.commit()
|
||||
print(entry)
|
||||
print(hash)
|
||||
conn.close()
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
docker run \
|
||||
-e POSTGRES_PASSWORD=test \
|
||||
-it \
|
||||
-v ./postgres:/var/lib/postgresql/data \
|
||||
-p 0.0.0.0:5432:5432 \
|
||||
postgres:14
|
Loading…
Reference in New Issue