Imoprt database in Windows WSL Linux into Power BI in Windows

本文介绍了一种在Windows11HomeEdition和WSL2LinuxUbuntu22.04.2LTS环境下,通过pg_dump和psqlAPI进行pgSQL数据库跨平台传输的方法,以及如何使用PowerBI连接并导入PostgreSQL数据库的过程。
摘要由CSDN通过智能技术生成

Abstract:

Windows WSL has long been renowned for powerful UNIX-like performance with lightwight OS. It also waived users from sophisticated network and other embedded configurations as WSL Linux shared same hardware sources with Windows. However, the vague design and layout of WSL is fatal for cross-platform cooperation, e.g. pgSQL database sharing and collaboration. This article tries to argue one possible solution for this demand.

Pre-Req:

Windows 11 Home Edition & WSL2 Linux Ubuntu 22.04.2 LTS

and:

PostgreSQL database completed in WSL

Relevant server and database settings completed in Windows

Method:

Two main APIs by pgSQL are used: pg_dump & psql, where pg_dump squeezes staff into .sql file and pg_restore unpacks .sql file back to database.

First, pg_dump

pg_dump -U postgres -h localhost -p 5432 -d db_name -format=custom -f db_name.sql

where user is set as "postgres", host as "localhost", port as "5432" by pg_dump flags (all as default). Notice that "format" flag is set as custom, because the output is defaulted to be .txt, which is uninterpretable by psql. You can give specific fiel location as well for -f flag.

.sql file is readable cross-platformly, making it key media in database transferring. 

Second, psql

 psql -U postgres -p 5432  -d db_name -f db_name.sql

psql command restores database from db_name.sql and the default location is in "postgres".

Finally, power BI

Go to the top toolbar and find "Get Data", then "More..." in the dropdown menu, then "Database" in the sidebar and finally, "PostgreSQL Database" and select "Connect". 

Note that in the following menu, server should be written as

"localhost" or "127.0.0.1"

instead of the name of your real server (kinds of like a bug?). Then tick the boxes that you want to import and then, finished!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值