22"""citus_dev
33
44Usage:
5- citus_dev make <name> [--size=<count>] [--port=<port>] [--use-ssl] [--no-extension] [--no-lib] [--destroy] [--init-with=<sql_file>] [--init-worker-with=<sql_file>] [--with-pgbouncer] [--fsync]
5+ citus_dev make <name> [--size=<count>] [--port=<port>] [--use-ssl] [--no-extension] [--no-lib] [--destroy] [--init-with=<sql_file>] [--init-worker-with=<sql_file>] [--with-pgbouncer] [--fsync] [--dbname=<database_name>]
66 citus_dev restart <name> [--watch]
77 citus_dev (start|stop) <name> [--force]
88
@@ -19,6 +19,7 @@ Options:
1919 --with-pgbouncer Setup pgbouncers between worker and coordinator (requires citus enterprise)
2020 --fsync Make data in citus_dev clusters safe across computer crashes (slower)
2121 --force Forceful shutdown
22+ --dbname=<database_name> Database name to create and use instead of default postgres database
2223
2324"""
2425from docopt import docopt
@@ -29,13 +30,13 @@ import subprocess
2930import sys
3031import getpass
3132import time
32- import distutils . spawn
33+ import shutil
3334
3435# for osx we might want to start postgres via a fixopen binary that preloads a
3536# dylib to fix the interrupted systemcall, this is done by changing the postgres
3637# path for pg_ctl to the fixopen binary
3738pgctl_flags = ""
38- fixopen = distutils . spawn . find_executable ("postgres.fixopen" )
39+ fixopen = shutil . which ("postgres.fixopen" )
3940if fixopen :
4041 pgctl_flags += f' -p "{ fixopen } "'
4142
@@ -159,22 +160,31 @@ def main(arguments):
159160 run (f'pg_ctl { pgctl_flags } start -D { clustername } /{ role } ' )
160161 port = cport
161162
163+ # Get the database name from arguments or use default
164+ dbname = arguments .get ('--dbname' )
165+
162166 if getpass .getuser () != 'postgres' and not os .getenv ('PGDATABASE' ):
163167 for i in range (size + 1 ):
164168 nodeport = port + i
165- run (f'createdb -p { nodeport } ' )
169+ if dbname :
170+ run (f'createdb -p { nodeport } { dbname } ' )
171+ else :
172+ run (f'createdb -p { nodeport } ' )
166173
167174 if not arguments ["--no-extension" ]:
175+ # Construct database connection parameter
176+ db_param = f' -d { dbname } ' if dbname else ''
177+
168178 for i in range (size + 1 ):
169179 nodeport = port + i
170- run (f'psql -p { nodeport } -c "CREATE EXTENSION citus;"' )
180+ run (f'psql -p { nodeport } { db_param } -c "CREATE EXTENSION citus;"' )
171181
172- run (f"psql -p { port } -c \" SELECT * from citus_set_coordinator_host('localhost', { port } );\" " )
182+ run (f"psql -p { port } { db_param } -c \" SELECT * from citus_set_coordinator_host('localhost', { port } );\" " )
173183
174184 for i in range (size ):
175185 workerport = port + 1 + i
176- run (f"psql -p { port } -c \" SELECT * from master_add_node('localhost', { workerport } );\" " )
177- run (f'psql -p { port } -c "SELECT * from master_get_active_worker_nodes();"' )
186+ run (f"psql -p { port } { db_param } -c \" SELECT * from master_add_node('localhost', { workerport } );\" " )
187+ run (f'psql -p { port } { db_param } -c "SELECT * from master_get_active_worker_nodes();"' )
178188
179189 if pgbouncer :
180190 # need to start pgbouncers and configure pg_dist_poolinfo
@@ -183,15 +193,15 @@ def main(arguments):
183193 workerPort = port + i + 1
184194 bouncerPort = port + i + 101
185195 run (f'pgbouncer -d { clustername } /worker{ i } .pgbouncer.ini' )
186- run (f"psql -p { coordinatorPort } -c \" INSERT INTO pg_dist_poolinfo SELECT nodeid, 'host=localhost port={ bouncerPort } ' AS poolinfo FROM pg_dist_node WHERE nodeport = { workerPort } ;\" " )
196+ run (f"psql -p { coordinatorPort } { db_param } -c \" INSERT INTO pg_dist_poolinfo SELECT nodeid, 'host=localhost port={ bouncerPort } ' AS poolinfo FROM pg_dist_node WHERE nodeport = { workerPort } ;\" " )
187197
188198
189199 if arguments ['--init-with' ]:
190- run (f'psql -p { cport } -f { arguments ["--init-with" ]} -v ON_ERROR_STOP=1' )
200+ run (f'psql -p { cport } { db_param } -f { arguments ["--init-with" ]} -v ON_ERROR_STOP=1' )
191201 if arguments ['--init-worker-with' ]:
192202 for i in range (size ):
193203 workerport = port + 1 + i
194- run (f'psql -p { workerport } -f { arguments ["--init-worker-with" ]} -v ON_ERROR_STOP=1' )
204+ run (f'psql -p { workerport } { db_param } -f { arguments ["--init-worker-with" ]} -v ON_ERROR_STOP=1' )
195205
196206 elif arguments ["stop" ]:
197207 clusterName = arguments ["<name>" ]
0 commit comments