https://slingdata.io logo
s
Hi! How can we use sling-data to transfer data from bigquery to postgres instance stored in Cloud SQL?
f
Hey @shootingstard. Yes should be able to. Check out the docs at https://docs.slingdata.io/connections/database-connections and give it a shot.
s
I read the doc but I see no documentation specifically for google Cloud SQL. In python I can use a google cloud sql python connecter lib or use the Google cloud sql auth proxy but I do not see how to set up that with sling?
to be more specific, my constraint is that I can't set up a google auth proxy on our production app (it is on dagster serveless instance so not possible to set up the auth proxy). What I can use is some service account credential but there is nothing in sling doc for postgres to give it from what I understand
f
@shootingstard. OK, this is implemented for next release. You can use the [dev build](https://github.com/slingdata-io/sling-cli?tab=readme-ov-file#automated-dev-builds) right now if you'd like. See updated [docs here](https://docs.slingdata.io/connections/database-connections/postgres#google-cloud-sql-iam-authentication-v1.4.25).
s
oh damn seems promising! However I think I will need to wait until the release because I can't easily change the container of prod Do you know more or less, when the next release will be released?
f
Yes, target is end of this week
s
you are a 👑
@flarco regarding the gcp_key_body: do you expect the base64 encoding of the json, or juste the json content with ""
f
raw string:
Copy code
POSTGRES_CLOUDSQL:
    type: postgres
    gcp_instance: my-instance
    gcp_project: my-project
    gcp_region: us-central1
    user: my-sa@my-project.gserviceaccount.com
    database: mydatabase
    gcp_key_body: |
      { "type": "service_account", ... }
s
oki because I will pass it as environment variables to dagster so I hope that it will handle escape line
we'll see haha
f
yeah, you can pass
SLING_ENV_YAML
with the whole yaml payload in there
s
@flarco should I create the user of my service account in the db?
Like that for example, but I thought the IAM removed the need for a password
Copy code
CREATE USER sling WITH PASSWORD '<password>';
GRANT CREATE ON DATABASE <database_name> TO sling;
f
Oh, that section is for regular postgers
yeah, you shoulnd't need password
s
oki because I have the following error : ~ failure running replication (see docs @ https://docs.slingdata.io/sling-cli) --------------------------- scraper.normalized_nutritional_data --------------------------- ~ could not ping Cloud SQL instance. Verify: 1) IAM auth flag 'cloudsql.iam_authentication=on', 2) SA 'dagster-prod-cloud-sql@happyhoursmarketdev.iam' has 'Cloud SQL Instance User' role, 3) SA added as IAM db user with full email, 4) DB privileges granted to 'dagster-prod-cloud-sql@happyhoursmarketdev.iam', 5) Credentials file valid and matches SA, 6) Cloud SQL Admin API enabled failed to connect to `user=dagster-prod-cloud-sql@happyhoursmarketdev.iam database=postgres`: 127.0.0.1:5432 (localhost): server error: FATAL: password authentication failed for user "dagster-prod-cloud-sql@happyhoursmarketdev.iam" which I do not understand
Like password auth failed but I should not need such password
f
yeah, i experienced that, the error message wasnt helpful. Can you check the Cloud SQL logs?
try to remove the
.iam
from user?
s
Copy code
yaml
  POSTGRES_DEV:
      type: postgres
      database : "{{ env.POSTGRES_DJANGO__DATABASE }}"
      gcp_instance : "{{ env.POSTGRES_DJANGO__INSTANCE }}"
      gcp_project : "{{ env.POSTGRES_DJANGO__PROJECT }}"
      gcp_region : "{{ env.POSTGRES_DJANGO__LOCATION }}"
      user : "dagster-prod-cloud-sql@happyhoursmarketdev.iam.gserviceaccount.com"
      gcp_key_body : | 
        { "type": "service_account", ...}
f
user name should match exactly what it is one CloudSQL Users panel
is it
dagster-prod-cloud-sql@happyhoursmarketdev
?
s
ah
for now there is no IAM user added in the db
I thought the use of a service account did that automaticallt
I will try addidnf it and see
Now I can connect because I added the IAM user to the db however I still have a : ERROR: permission denied for database postgres (SQLSTATE 42501) So I suppose I have to add the IAM user permissions on the db through sql, will try that
thanks a lot for all your help
Almost there!
I just stille have this error :
Copy code
~ failure running replication (see docs @ https://docs.slingdata.io/sling-cli)
--------------------------- scraper.normalized_nutritional_data ---------------------------


~ could not execute statement
sql: expected 0 arguments, got 31

~ could not insert into "public"."normalized_nutritional_data_tmp"
~ could not COPY into table "public"."normalized_nutritional_data_tmp"
sql: expected 0 arguments, got 31

~ could not execute statement
sql: expected 0 arguments, got 31
  File "/home/loic-quivron/Documents/repos/production/hhm_dagster_prod/.venv/lib/python3.12/site-packages/sling/__init__.py", line 445, in _run
    for line in _exec_cmd(cmd, env=env, stdin=stdin):
  File "/home/loic-quivron/Documents/repos/production/hhm_dagster_prod/.venv/lib/python3.12/site-packages/sling/__init__.py", line 527, in _exec_cmd
    raise Exception("Sling command failed:\n" + "\n".join(lines))
f
oh, can you run with env var
DEBUG=true
? this will give more details.
will try using gs_bucket as string
chat gpt tells me it might be dollar characters in my source table
f
interesing. Can you change your replication to not use COPY, just to test:
Copy code
streams:
  scraper.normalized_nutritional_data:
    target_options:
      use_bulk: false
s
It works!
yeah!
from what I understood from chatgpt it might have been escaped characters like '$' that prevent the use of COPY but I tried on another table without any of those "$" characters and it did the same error
It's already super nice that I managed to copy the data row by row thanks a lot for all your help!
f
Great, but this wont scale for massive tables. It actually has to do with the IAM connector. The golang driver needs a separate logic to use another COPY for bulk loading into PG using IAM. I'll look into that for next release in a few weeks.
s
you're a chad!