mirror of
https://github.com/wader/fq.git
synced 2024-12-02 12:45:53 +03:00
3.2 KiB
3.2 KiB
How to generate PostgreSQL test data
1) install postgres
Use this links to add repository and install PostgreSQL:
- https://www.postgresql.org/download/linux/
- https://www.postgresql.org/download/linux/redhat/
- https://www.postgresql.org/download/linux/debian/
You may install PostgreSQL with OS repository. But it may contains not all versions of PostgreSQL.
2) use default intallation location of postgres.
If you don't want default location. You may remove cluster and init it again.
# Detect PGDATA location:
ps aux | grep postgre
postgres 887 0.0 0.0 4334456 13608 ? Ss 07:48 0:00 /usr/pgsql-14/bin/postmaster -D /u02/data
Result is:
- /u02/data - is PGDATA location
- /usr/pgsql-14/bin - location of PostgreSQL bin
3) init tables
# use postgres user
sudo su postgres
# then init pgbench tables
/usr/pgsql-14/bin/pgbench -i
# run simple test
/usr/pgsql-14/bin/pgbench -T 60 -j 100
4) run commands in psql
# start psql
/usr/pgsql-14/bin/psql
# display tables
\dt+
Schema | Name | Type | Owner | Persistence | Access method | Size | Description
--------+------------------+-------+----------+-------------+---------------+--------+-------------
public | pgbench_accounts | table | postgres | permanent | heap | 13 MB |
public | pgbench_branches | table | postgres | permanent | heap | 40 kB |
public | pgbench_history | table | postgres | permanent | heap | 968 kB |
public | pgbench_tellers | table | postgres | permanent | heap | 40 kB |
# run CHECKPOINT to avoid partially written data
CHECKPOINT;
# detect location of tables
SELECT pg_relation_filepath('pgbench_history');
pg_relation_filepath
----------------------
base/13746/24599
base/13746/24599 - location of table in PGDATA
5) use root account to copy table file
# login in root
sudo su
# go to PGDATA
cd /u02/data
# copy table file
cp base/13746/24599 /home/user
# change persmissions
chwon user:user /home/user/24599
chmod 644 /home/user/24599
6) Copy tables files to local with scp
scp user@192.168.0.100:~/24599 .
7) You may want to cut 2 pages (8192 * 2) from table
head -c 16384 ./245991 > ./24599_2pages
8) Locate pg_control file
global/pg_control
inside PGDATA
9) Locate btree index
Get info about index:
\d pgbench_accounts
Table "public.pgbench_accounts"
Column | Type | Collation | Nullable | Default
----------+---------------+-----------+----------+---------
aid | integer | | not null |
bid | integer | | |
abalance | integer | | |
filler | character(84) | | |
Indexes:
"pgbench_accounts_pkey" PRIMARY KEY, btree (aid)
Then get path of pgbench_accounts_pkey:
select pg_relation_filepath('pgbench_accounts_pkey');
pg_relation_filepath
----------------------
base/13746/24596
base/13746/24596
- is a path inside PGDATA of btree index pgbench_accounts_pkey.