Skip to content

Commit

Permalink
establish sql connection to cardano db
Browse files Browse the repository at this point in the history
  • Loading branch information
sadMaxim committed Oct 9, 2023
1 parent 56ee7db commit 409d0a4
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ cluster
!cluster/Dockerfile
!cluster/start-node.sh
tmp
secrets
.ipynb_checkpoints
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
pkgs.nixpkgs-fmt
cardano.legacyPackages.${system}.cardano-cli
cardano.legacyPackages.${system}.cardano-node
];
postgresql_14
] ++ (with pkgs.python310Packages; [jupyterlab pandas psycopg2]);
shellHook = ''
'';
};
Expand Down
22 changes: 22 additions & 0 deletions research/congestion-periods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@
- https://cexplorer.io/usage
- Cardano is currently at 94% load!Only 6% left until Cardano is at max capacityWhat does that mean, and how can you be prepared pic.twitter.com/1TZsIUg10N — Sebastien Guillemot (@SebastienGllmt) May 8, 2023

# Collect transaction' statistic from blocks
- Connect to remote server: `ssh cardano-cli@node-1.mainnet.ctl-runtime.staging.mlabs.city`. Connect to db: `psql -U cexplorer -d cdbsync`.

--table with transactions
select * from tx limit 10;

--all tables and columns

SELECT
t.tablename AS table_name,
a.attname AS column_name
FROM
pg_tables t
JOIN
pg_attribute a ON t.tablename = a.attrelid::regclass::text
WHERE
t.tableowner = 'cexplorer'
AND a.attnum > 0
AND NOT a.attisdropped
ORDER BY
t.tablename,
a.attnum;
87 changes: 87 additions & 0 deletions research/statistics.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "4ebc5b96-d76a-4b3a-b95b-ddcec048cd61",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import psycopg2 \n",
"import os"
]
},
{
"cell_type": "markdown",
"id": "867283ef-18fd-4777-b3a2-eacb0620fb2c",
"metadata": {},
"source": [
"run `ssh -L 5433:localhost:5432 cardano-cli@node-1.mainnet.ctl-runtime.staging.mlabs.city -N` \n",
"to establish ssh tunnel\n"
]
},
{
"cell_type": "markdown",
"id": "4931d90b-fb94-41f3-a93c-cc6470121f63",
"metadata": {},
"source": [
"or to forward socket:\n",
"`mkdir /tmp/sql-socket`\n",
"`ssh -L /tmp/sql-socket/.s.PGSQL.5432:/run/postgresql/.s.PGSQL.5432 -N cardano-cli@node-1.mainnet.ctl-runtime.staging.mlabs.city`\n",
"`psql -h /tmp/sql-socket -U cexplorer -d cdbsync`\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "484bb966-da11-4e7e-a98d-d87ea283b191",
"metadata": {},
"outputs": [],
"source": [
"conn = psycopg2.connect(\n",
" dbname='cdbsync',\n",
" user='cexplorer',\n",
" host='localhost',\n",
" port=5433\n",
")\n",
"\n",
"cursor = conn.cursor()\n",
"cursor.execute('SELECT version();')\n",
"print(cursor.fetchone())\n",
"\n",
"cursor.close()\n",
"conn.close()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7f8d2465-78d5-4f3b-9d89-3c4c7763de12",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 409d0a4

Please sign in to comment.