Flyctl now supports managing users using the fly mpg users command.
$ fly mpg users create
? Select Organization: Akshit Garg (personal)
? Select a Postgres cluster pgpgpg-old-surf-5969-db [dzx6qo6e42j0jpv5] (ams)
? Enter username: test-user
? Select user role: writer
Creating user test-user with role writer in cluster dzx6qo6e42j0jpv5...
User created successfully!
Name: test-user
Role: writer
$ fly mpg users list
NAME ROLE
fly-user schema_admin
test-user writer
$ fly mpg users set-role dzx6qo6e42j0jpv5 -u test-user
? Select user role: schema_admin
Updating user test-user role to schema_admin in cluster dzx6qo6e42j0jpv5...
User role updated successfully!
Name: test-user
Role: schema_admin
$ fly mpg users delete dzx6qo6e42j0jpv5 -u test-user
Deleting a user is not reversible.
? Delete user test-user from cluster dzx6qo6e42j0jpv5? Yes
Deleting user test-user from cluster dzx6qo6e42j0jpv5...
User test-user deleted successfully from cluster dzx6qo6e42j0jpv5
It also supports managing databases in a cluster using flyctl mpg databases
$ fly mpg databases list dzx6qo6e42j0jpv5
NAME
fly-db
foobar
helloworld
$ fly mpg databases create dzx6qo6e42j0jpv5
? Enter database name: foo
Creating database foo in cluster dzx6qo6e42j0jpv5...
Database created successfully!
Name: foo
Like other commands, they prompt for cluster, username and other flags if required.
You can also specify a database and user when using fly mpg connect and fly mpg attach.
$ fly mpg connect
? Select Organization: Akshit Garg (personal)
? Select a Postgres cluster pgpgpg-old-surf-5969-db [dzx6qo6e42j0jpv5] (ams)
? Select user: test-user [reader]
? Select database: foobar
Proxying localhost:16380 to remote [fdaa:a:5ef2:0:1::108]:5432
psql (14.19 (Homebrew), server 16.8 - Percona Distribution)
WARNING: psql major version 14, server major version 16.
Some psql features might not work.
Type "help" for help.
foobar=> \conninfo
You are connected to database "foobar" as user "test-user" on host "localhost" (address "::1") at port "16380".
$ fly mpg attach
Listing clusters in organization akshit-garg-798
? Select a Postgres cluster pgpgpg-old-surf-5969-db [dzx6qo6e42j0jpv5] (ams)
? Select user: test-user [schema_admin]
? Select database: fly-db
Postgres cluster dzx6qo6e42j0jpv5 is being attached to pgpgpg-old-surf-5969
The following secret was added to pgpgpg-old-surf-5969:
DATABASE_URL=postgresql://test-user:<redacted>@pgbouncer.dzx6qo6e42j0jpv5.flympg.net/fly-db
These features are available starting flyctl v0.3.211