databse init script
This commit is contained in:
parent
0627a1caea
commit
74af277ea0
28
README.md
28
README.md
|
@ -1,19 +1,17 @@
|
|||
# TO INSTALL POSTGRES SCHEMA AND DATABASE
|
||||
# BankingStage Sidecar
|
||||
This is a sidecar application for the BankingStage project. It is responsible for importing data from the Solana blockchain into the PostgreSQL database.
|
||||
Data is retrieved via Solana RPC and Geysers gRPC API.
|
||||
|
||||
sudo -u postgres psql postgres
|
||||
###### in postgres
|
||||
create data
|
||||
create database mangolana;
|
||||
grant all privileges on database mangolana to galactus;
|
||||
## Database Configuration
|
||||
### Database Roles
|
||||
* `bankingstage_dashboard` - read-only access to the database for the dashboard web application
|
||||
* `bankingstage_sidecar` - write access to the database for the sidecar importer
|
||||
|
||||
### Configure sidecar PostgreSQL connection
|
||||
export PG_CONFIG="host=localhost dbname=bankingstage user=bankingstage_dashboard password=test sslmode=disable"
|
||||
|
||||
psql -d mangolana < migration.sql
|
||||
### Database Schema
|
||||
The database schema is defined in the [migration.sql](migration.sql) file.
|
||||
For new database installations start with the [init-database.sql](init-database.sql) file.
|
||||
Required is a PostgreSQL database (tested version 15).
|
||||
|
||||
export PG_CONFIG="host=localhost dbname=mangolana user=galactus password=test sslmode=disable"
|
||||
|
||||
### give rights to user
|
||||
|
||||
GRANT ALL PRIVILEGES ON DATABASE mangolana TO galactus;
|
||||
GRANT ALL PRIVILEGES ON SCHEMA banking_stage_results TO galactus;
|
||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA banking_stage_results TO galactus;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA banking_stage_results GRANT ALL PRIVILEGES ON TABLES TO galactus;
|
|
@ -0,0 +1,26 @@
|
|||
-- setup new postgresql database; tested with PostgreSQL 15
|
||||
|
||||
-- CREATE DATABASE bankingstage3a
|
||||
-- run migration.sql
|
||||
|
||||
-- setup sidecar user
|
||||
GRANT CONNECT ON DATABASE bankingstage3a TO bankingstage_sidecar;
|
||||
ALTER USER bankingstage_sidecar CONNECTION LIMIT 10;
|
||||
GRANT USAGE ON SCHEMA banking_stage_results_2 TO bankingstage_sidecar;
|
||||
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA banking_stage_results_2 TO bankingstage_sidecar;
|
||||
ALTER DEFAULT PRIVILEGES IN SCHEMA banking_stage_results_2 GRANT ALL PRIVILEGES ON TABLES TO bankingstage_sidecar;
|
||||
GRANT USAGE ON ALL SEQUENCES IN SCHEMA banking_stage_results_2 TO bankingstage_sidecar;
|
||||
|
||||
|
||||
-- setup query_user
|
||||
GRANT CONNECT ON DATABASE bankingstage3a TO query_user;
|
||||
ALTER USER query_user CONNECTION LIMIT 5;
|
||||
GRANT USAGE ON SCHEMA banking_stage_results_2 TO query_user;
|
||||
GRANT SELECT ON ALL TABLES in SCHEMA banking_stage_results_2 TO query_user;
|
||||
|
||||
|
||||
-- setup bankingstage_dashboard
|
||||
GRANT CONNECT ON DATABASE bankingstage3a TO bankingstage_dashboard;
|
||||
ALTER USER bankingstage_sidecar CONNECTION LIMIT 10;
|
||||
GRANT USAGE ON SCHEMA banking_stage_results_2 TO bankingstage_dashboard;
|
||||
GRANT SELECT ON ALL TABLES in SCHEMA banking_stage_results_2 TO bankingstage_dashboard;
|
|
@ -1,3 +1,5 @@
|
|||
-- for initial database setup start with init-database.sql
|
||||
|
||||
CREATE SCHEMA banking_stage_results_2;
|
||||
|
||||
CREATE TABLE banking_stage_results_2.transactions(
|
||||
|
@ -112,18 +114,6 @@ insert into banking_stage_results_2.errors (error_text, error_code) VALUES
|
|||
('WouldExceedMaxBlockCostLimit', 34),
|
||||
('WouldExceedMaxVoteCostLimit', 35);
|
||||
|
||||
CLUSTER banking_stage_results_2.blocks using blocks_pkey;
|
||||
VACUUM FULL banking_stage_results_2.blocks;
|
||||
-- optional
|
||||
CLUSTER banking_stage_results_2.transaction_slot using idx_transaction_slot_timestamp;
|
||||
VACUUM FULL banking_stage_results_2.transaction_slot;
|
||||
|
||||
CLUSTER banking_stage_results_2.accounts_map_transaction using accounts_map_transaction_pkey;
|
||||
|
||||
CLUSTER banking_stage_results_2.transactions using transactions_pkey;
|
||||
|
||||
CLUSTER banking_stage_results_2.accounts using accounts_pkey;
|
||||
|
||||
CREATE TABLE banking_stage_results_2.accounts_map_transaction_latest(
|
||||
acc_id BIGINT PRIMARY KEY,
|
||||
-- sorted: oldest to latest, max 1000
|
||||
|
|
Loading…
Reference in New Issue