Hey all! Meltano target-postgres ignores port conf...
# troubleshooting
a
Hey all! Meltano target-postgres ignores port configuration Details inside
If I run postgres in container (note port forwarding): $ sudo docker run -p 5431:5432 -e POSTGRES_USER=meltano -e POSTGRES_PASSWORD=password --name meltano_postgres -d postgres and connects through $ pgcli -h localhost -p 5431 -u meltano -d postgres everything works. Then I set up target postgres: $ meltano config target-postgres set user meltano $ meltano config target-postgres set password password $ meltano config target-postgres set database postgres $ meltano config target-postgres set add_metadata_columns True $ meltano config target-postgres set host localhost $ meltano config target-postgres set port 5431 and then connects it fails with those errors (note port): $ meltano elt tap-stackexchange target-postgres
2023-01-26T182553.979110Z [info ] sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (::1), port 5432 failed: Connection refused cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.979242Z [info ] Is the server running on that host and accepting TCP/IP connections? cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.979593Z [info ] connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.979860Z [info ] Is the server running on that host and accepting TCP/IP connections? cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.980080Z [info ] connection to server at "localhost" (127.0.1.1), port 5432 failed: Connection refused cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.980247Z [info ] Is the server running on that host and accepting TCP/IP connections? cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.980603Z [info ] cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
2023-01-26T182553.980799Z [info ] (Background on this error at: https://sqlalche.me/e/14/e3q8) cmd_type=loader name=target-postgres run_id=68edb5bd-d721-4512-aa05-89460dddc114 state_id=2023-01-26T182551--tap-stackexchange--target-postgres stdio=stderr
if I change postgres port to standard 5432 and target-postgres' configuration port to 5432 everything works: $ sudo docker kill %hash% $ sudo docker run -p 5432:5432 -e POSTGRES_USER=meltano -e POSTGRES_PASSWORD=password --name meltano_postgres -d postgres $ meltano config target-postgres set port 5432 $ meltano elt tap-stackexchange target-postgres
blah blah ...
Extract & load complete!
How to make meltano use configured port? Is there any other place where it could be configured?
c
It's the wrong config option. The option is called
sqlalchemy_url
https://hub.meltano.com/extractors/tap-postgres--meltanolabs/#sqlalchemy_url-setting
You can also print the available settings and their current values with the
meltano config tap-postgres list
command https://docs.meltano.com/reference/command-line-interface#config
a
@christoph unfortunately, this option is unset but something still overrides port value
$ meltano config target-postgres list 2023-01-27T061044.043795Z [info ] The default environment 'dev' will be ignored for
meltano config
. To configure a specific environment, please use the option
--environment=<environment name>
. host [env: TARGET_POSTGRES_HOST] current value: 'localhost' (from
meltano.yml
) Host: Hostname for postgres instance. Note if sqlalchemy_url is set this will be ignored. port [env: TARGET_POSTGRES_PORT] current value: 5431 (from
meltano.yml
) Port: The port on which postgres is awaiting connection. Note if sqlalchemy_url is set this will be ignored. Defaults to 5432 user [env: TARGET_POSTGRES_USER] current value: 'meltano' (from
meltano.yml
) User: User name used to authenticate. Note if sqlalchemy_url is set this will be ignored. password [env: TARGET_POSTGRES_PASSWORD] current value: 'password' (from the TARGET_POSTGRES_PASSWORD variable in
.env
) Password: Password used to authenticate. Note if sqlalchemy_url is set this will be ignored. database [env: TARGET_POSTGRES_DATABASE] current value: 'postgres' (from
meltano.yml
) Database: Database name. Note if sqlalchemy_url is set this will be ignored. sqlalchemy_url [env: TARGET_POSTGRES_SQLALCHEMY_URL] current value: None (default) Sqlalchemy Url: SQLAlchemy connection string. This will override using host, user, password, port,dialect. Note that you must esacpe password specialcharacters properly seehttps://docs.sqlalchemy.org/en/20/core/engines.html#escaping-special-characters-such-as-signs-in-passwords dialect+driver [env: TARGET_POSTGRES_DIALECT_DRIVER] current value: None (default) Dialect+Driver: Dialect+driver see https://docs.sqlalchemy.org/en/20/core/engines.html. Generally just leave this alone. Note if sqlalchemy_url is set this will be ignored. default_target_schema [env: TARGET_POSTGRES_DEFAULT_TARGET_SCHEMA] current value: None (default: '$MELTANO_EXTRACT__LOAD_SCHEMA') Default Target Schema: Postgres schema to send data to, example: tap-clickup stream_maps [env: TARGET_POSTGRES_STREAM_MAPS] current value: None (default) Stream Maps: Config object for stream maps capability. For more information check out Stream Maps. stream_map_config [env: TARGET_POSTGRES_STREAM_MAP_CONFIG] current value: None (default) Stream Map Config: User-defined config values to be used within map expressions. flattening_enabled [env: TARGET_POSTGRES_FLATTENING_ENABLED] current value: None (default) Flattening Enabled: 'True' to enable schema flattening and automatically expand nested properties. flattening_max_depth [env: TARGET_POSTGRES_FLATTENING_MAX_DEPTH] current value: None (default) Flattening Max Depth: The max depth to flatten schemas. Custom, possibly unsupported by the plugin: add_metadata_columns [env: TARGET_POSTGRES_ADD_METADATA_COLUMNS] current value: 'True' (from
meltano.yml
)
$ echo $TARGET_POSTGRES_SQLALCHEMY_URL gives nothing as well
c
Oh. Sorry. I got confused! My bad. I gave you the documentation for
tap-postgres
instead of
target-postgres
..... Ignore my
sqlalchemy_url
comment from earlier ...
Your initial configuration steps were perfectly correct.
Changing the port number is actually not implemented at the moment in the MeltanoLabs
target-postgres
....
Just doing a quick cc: @BuzzCutNorman @visch
a
hmm, thanks. in that case it seems strange that port can be set by user explicitly but this configuration will be ignored
c
It's a bug
a
should I report it somehow? or this description here should be enough?
c
I've left a quick comment in the catch-all tracking issue under which the original feature was implemented https://github.com/MeltanoLabs/target-postgres/issues/4
So, in order to get you going, you can remove all your existing connection-related settings for
target_postgres
(
host
,
password
,
user
,
database
,
port
) and replace it with the (currently undocumented)
sqlalchemy_url
configuration setting
Your
sqlalchemy_url
setting should be
<postgres+psycopg2://meltano:password@localhost:5431/postgres>
a
thanks for this workaround
Hello, @christoph Unfortunately, sqlalchemy_url doesn't work at the moment: Loader fails at
Copy code
2023-01-29T09:15:25.003174Z [info     ]    * Required key is missing from config: [user] cmd_type=elb consumer=True name=target-postgres producer=False stdio=stderr string_id=target-postgres
2023-01-29T09:15:25.003633Z [info     ]    * Required key is missing from config: [password] cmd_type=elb consumer=True name=target-postgres producer=False stdio=stderr string_id=target-postgres
2023-01-29T09:15:25.004025Z [info     ]    * Required key is missing from config: [dbname] cmd_type=elb consumer=True name=target-postgres producer=False stdio=stderr string_id=target-postgres
$ meltano config target-postgres list tells me that sqlalchemy_url could be unsupported by now and it seems that it is
Copy code
possibly unsupported by the plugin:
sqlalchemy_url [env: TARGET_POSTGRES_SQLALCHEMY_URL] current value: '<postgres+psycopg2://meltano:password@localhost:5431/postgres>' (from `meltano.yml`)
v
https://github.com/MeltanoLabs/target-postgres/issues/93 I put this in for you @aleksei_razvodov , smells like a target bug but not sure. Should be quick so I"ll take a look.
https://github.com/MeltanoLabs/target-postgres/pull/95 has a fix for the Port issue. Setting sqlalchemy_url does work just fine as long as you're not setting any of the other values for target-postgres (host, port etc).
a
Thanks for the help, @visch
v
Hope you get up and running! Thanks for sharing your issue