@@ -75,6 +75,12 @@ pub fn cli() -> clap::Command {
75
75
"The maximum size of the page pool in bytes. Should be a multiple of 64KiB. The default is 8GiB." ,
76
76
) ,
77
77
)
78
+ . arg (
79
+ Arg :: new ( "pg_port" )
80
+ . long ( "pg-port" )
81
+ . help ( "If specified, enables the built-in PostgreSQL wire protocol server on the given port." )
82
+ . value_parser ( clap:: value_parser!( u16 ) . range ( 1024 ..65535 ) ) ,
83
+ )
78
84
// .after_help("Run `spacetime help start` for more detailed information.")
79
85
}
80
86
@@ -94,6 +100,7 @@ impl ConfigFile {
94
100
95
101
pub async fn exec ( args : & ArgMatches , db_cores : JobCores ) -> anyhow:: Result < ( ) > {
96
102
let listen_addr = args. get_one :: < String > ( "listen_addr" ) . unwrap ( ) ;
103
+ let pg_port = args. get_one :: < u16 > ( "pg_port" ) ;
97
104
let cert_dir = args. get_one :: < spacetimedb_paths:: cli:: ConfigDir > ( "jwt_key_dir" ) ;
98
105
let certs = Option :: zip (
99
106
args. get_one :: < PubKeyPath > ( "jwt_pub_key_path" ) . cloned ( ) ,
@@ -181,21 +188,32 @@ pub async fn exec(args: &ArgMatches, db_cores: JobCores) -> anyhow::Result<()> {
181
188
182
189
let tcp = TcpListener :: bind ( listen_addr) . await ?;
183
190
socket2:: SockRef :: from ( & tcp) . set_nodelay ( true ) ?;
184
- log:: debug!( "Starting SpacetimeDB listening on {}" , tcp. local_addr( ) ?) ;
185
- let pg_server_addr = format ! ( "{}:5432" , listen_addr. split( ':' ) . next( ) . unwrap( ) ) ;
186
- let tcp_pg = TcpListener :: bind ( pg_server_addr) . await ?;
191
+ log:: info!( "Starting SpacetimeDB listening on {}" , tcp. local_addr( ) ?) ;
192
+
193
+ if let Some ( pg_port) = pg_port {
194
+ let server_addr = listen_addr. split ( ':' ) . next ( ) . unwrap ( ) ;
195
+ let tcp_pg = TcpListener :: bind ( format ! ( "{server_addr}:{pg_port}" ) ) . await ?;
187
196
188
- let notify = Arc :: new ( tokio:: sync:: Notify :: new ( ) ) ;
189
- let shutdown_notify = notify. clone ( ) ;
190
- tokio:: select! {
191
- _ = pg_server:: start_pg( notify. clone( ) , ctx, tcp_pg) => { } ,
192
- _ = axum:: serve( tcp, service) . with_graceful_shutdown( async move {
193
- shutdown_notify. notified( ) . await ;
194
- } ) => { } ,
195
- _ = tokio:: signal:: ctrl_c( ) => {
196
- println!( "Shutting down servers..." ) ;
197
- notify. notify_waiters( ) ; // Notify all tasks
197
+ let notify = Arc :: new ( tokio:: sync:: Notify :: new ( ) ) ;
198
+ let shutdown_notify = notify. clone ( ) ;
199
+ tokio:: select! {
200
+ _ = pg_server:: start_pg( notify. clone( ) , ctx, tcp_pg) => { } ,
201
+ _ = axum:: serve( tcp, service) . with_graceful_shutdown( async move {
202
+ shutdown_notify. notified( ) . await ;
203
+ } ) => { } ,
204
+ _ = tokio:: signal:: ctrl_c( ) => {
205
+ println!( "Shutting down servers..." ) ;
206
+ notify. notify_waiters( ) ; // Notify all tasks
207
+ }
198
208
}
209
+ } else {
210
+ log:: warn!( "PostgreSQL wire protocol server disabled" ) ;
211
+ axum:: serve ( tcp, service)
212
+ . with_graceful_shutdown ( async {
213
+ tokio:: signal:: ctrl_c ( ) . await . expect ( "failed to install Ctrl+C handler" ) ;
214
+ log:: info!( "Shutting down server..." ) ;
215
+ } )
216
+ . await ?;
199
217
}
200
218
201
219
Ok ( ( ) )
0 commit comments