PostgreSQL/PgLoader: Difference between revisions
Jump to navigation
Jump to search
Created page with "==Playground== {| |valign='top'| |valign='top'| |valign='top'| |- |colspan='3'| ---- |- |valign='top'| |valign='top'| |valign='top'| |} == References== {| |valign="top"| * [https://www.digitalocean.com/community/tutorials/how-to-migrate-mysql-database-to-postgres-using-pgloader PostgreSQL » PgLoader » Migrate From MySQL] * PostgreSQL » PgBouncer * [https://github.com/dimitri/pgloader PostgreSQL » PgLoader] * Helm/PostgreSQL|PostgreSQ..." |
No edit summary |
||
| (18 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | {|class='wikitable' | ||
{| | |valign='top' style='width:50%'| | ||
<syntaxhighlight lang='bash'> | |||
cat << EXE | sudo bash | |||
apt-get update;echo | |||
apt list -a --upgradable | |||
apt-get install -y pgloader | |||
EXE | |||
</syntaxhighlight> | |||
|valign='top' style='width:50%'| | |||
|- | |||
|valign='top' colspan='2'| | |||
{|class='wikitable mw-collapsible mw-collapsed' | |||
!scope='col' style='text-align:left'| | |||
Diagram | |||
|- | |||
|valign='top'| | |valign='top'| | ||
<kroki lang='plantuml'> | |||
@startuml | |||
!theme plain | |||
' Styling for Transparency and Layout | |||
skinparam backgroundColor transparent | |||
skinparam DefaultFontName Helvetica | |||
skinparam componentStyle uml2 | |||
skinparam packageStyle rectangle | |||
skinparam actorStyle awesome | |||
skinparam shadowing false | |||
skinparam databaseBackgroundColor #LightBlue | |||
skinparam arrowColor #DarkSlateGray | |||
package "Source Databases" { | |||
database "MariaDB / MySQL" as MariaDB #LightYellow | |||
database "Oracle Database" as Oracle #DarkSalmon | |||
database "SQLite / MSSQL / CSV" as Others #White | |||
} | |||
node "Migration Engine" { | |||
component [pgloader] as PGL #DeepSkyBlue | |||
} | |||
database "PostgreSQL" as Postgres #SteelBlue | |||
' Connections | |||
MariaDB -down-> PGL : " Reads Schema & Data " | |||
Oracle -down-> PGL : " Data Casting " | |||
Others -down-> PGL : " ETL Transformation " | |||
PGL -down-> Postgres : " LOAD DATA (Copy Protocol) " | |||
|valign='top'| | note right of PGL | ||
**Key Features:** | |||
* Fully Automated Schema Discovery | |||
* On-the-fly Data Type Casting | |||
* Parallel Data Loading | |||
* Continuous Migration (CDC) | |||
end note | |||
@enduml | |||
</kroki> | |||
|} | |||
|} | |||
==Migration== | |||
{|class='wikitable mw-collapsible' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Migration | |||
|- | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang='sql'> | |||
cat << DDL | mariadb | |||
CREATE DATABASE IF NOT EXISTS academia; | |||
CREATE USER 'chorke'@'%' IDENTIFIED BY 'sadaqah!'; | |||
GRANT ALL PRIVILEGES ON academia.* TO 'chorke'@'%'; | |||
FLUSH PRIVILEGES; | |||
DDL | |||
</syntaxhighlight> | |||
|valign='top'| | |valign='top' style='width:50%'| | ||
<syntaxhighlight lang='sql'> | |||
cat << DDL | psql | |||
CREATE DATABASE academia; | |||
CREATE USER chorke WITH ENCRYPTED PASSWORD 'sadaqah!'; | |||
GRANT ALL PRIVILEGES ON DATABASE academia TO chorke; | |||
ALTER DATABASE academia OWNER TO chorke; | |||
DDL | |||
</syntaxhighlight> | |||
|- | |||
|valign='top' colspan='2'| | |||
<syntaxhighlight lang='bash'> | |||
BKP_DATE_N_TIME="$(TZ=UTC-8 date +'%Y-%m-%dT%H%M')" | |||
echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD; echo | |||
# password: sadaqah! | |||
mariadb -h127.0.0.1 -P3306 -uchorke -Dacademia | |||
mariadb-dump -h127.0.0.1 -P3306 -uchorke -Bacademia > ./academia-${BKP_DATE_N_TIME}.dump | |||
mariadb -h127.0.0.1 -P3306 -uchorke -Dacademia < ./academia-20241010-T1010-ZP0600.dump | |||
</syntaxhighlight> | |||
|- | |- | ||
|colspan=' | |valign='top' colspan='2'| | ||
- | <syntaxhighlight lang='bash'> | ||
cat <<MIG | pgloader -v /dev/stdin | |||
LOAD DATABASE | |||
FROM mysql://chorke:sadaqah!@localhost/academia?useSSL=false | |||
INTO pgsql://chorke:sadaqah!@localhost/academia; | |||
MIG | |||
</syntaxhighlight> | |||
|- | |- | ||
|valign='top'| | |valign='top' colspan='2'| | ||
<syntaxhighlight lang='bash'> | |||
BKP_DATE_N_TIME="$(TZ=UTC-8 date +'%Y-%m-%dT%H%M')" | |||
echo -n password: ;read -s PGPASSWORD;export PGPASSWORD;echo | |||
# password: sadaqah! | |||
psql -h127.0.0.1 -p5432 -Uchorke -dacademia | |||
pg_dump -h127.0.0.1 -p5432 -Uchorke -dacademia | gzip > academia-${BKP_DATE_N_TIME}.sql.gz | |||
gunzip -c academia-20241010-T1010-ZP0600.sql.gz | psql -h127.0.0.1 -p5432 -Uchorke -dacademia | |||
</syntaxhighlight> | |||
|} | |||
==Playground== | |||
{|class='wikitable mw-collapsible' | |||
!scope='col' style='text-align:left' colspan='2'| | |||
Playground | |||
|- | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang='bash'> | |||
docker run --rm -it ghcr.io/dimitri/pgloader:latest pgloader -h | |||
docker run --rm -it ghcr.io/dimitri/pgloader:latest pgloader -V | |||
</syntaxhighlight> | |||
|valign='top' style='width:50%'| | |||
<syntaxhighlight lang='bash'> | |||
pgloader -h | |||
pgloader -V | |||
</syntaxhighlight> | |||
|- | |||
|valign='top' colspan='2'| | |||
<syntaxhighlight lang='bash'> | |||
pgloader ./sqlite/academia.db pgsql:///academia | |||
pgloader ./sqlite/academia.db pgsql://chorke:sadaqah!@localhost/academia | |||
</syntaxhighlight> | |||
|- | |||
|valign='top' colspan='2'| | |||
<syntaxhighlight lang='bash'> | |||
pgloader mysql://chorke:sadaqah!@localhost/academia pgsql:///academia | |||
pgloader mysql://chorke:sadaqah!@localhost/academia pgsql://chorke:sadaqah!@localhost/academia | |||
</syntaxhighlight> | |||
|- | |||
|valign='top'| | |valign='top'| | ||
<syntaxhighlight lang='bash'> | |||
cat <<MIG | pgloader -v /dev/stdin | |||
LOAD DATABASE | |||
FROM mysql://chorke:sadaqah!@localhost/academia?useSSL=false | |||
INTO pgsql://chorke:sadaqah!@localhost/academia | |||
WITH include drop, create tables | |||
ALTER SCHEMA 'academia' RENAME TO 'public'; | |||
MIG | |||
</syntaxhighlight> | |||
|valign='top'| | |valign='top'| | ||
|} | |} | ||
== References== | ==References== | ||
{| | {|class='wikitable mw-collapsible' | ||
|valign= | !scope='col' style='text-align:left' colspan='3'| | ||
References | |||
|- | |||
|valign='top' style='width:33%'| | |||
* [https://www.digitalocean.com/community/tutorials/how-to-migrate-mysql-database-to-postgres-using-pgloader PostgreSQL » PgLoader » Migrate From MySQL] | * [https://www.digitalocean.com/community/tutorials/how-to-migrate-mysql-database-to-postgres-using-pgloader PostgreSQL » PgLoader » Migrate From MySQL] | ||
* [[PostgreSQL/PgBouncer|PostgreSQL » PgBouncer]] | * [[PostgreSQL/PgBouncer|PostgreSQL » PgBouncer]] | ||
| Line 28: | Line 174: | ||
* [[PostgreSQL]] | * [[PostgreSQL]] | ||
|valign= | |valign='top' style='width:34%'| | ||
|valign= | |valign='top' style='width:33%'| | ||
|- | |- | ||
|valign='top'| | |||
|valign= | |||
* [[Academia JavaEE Workspace in Ubuntu]] | * [[Academia JavaEE Workspace in Ubuntu]] | ||
* [[IntelliJ IDEA]] | * [[IntelliJ IDEA]] | ||
| Line 48: | Line 191: | ||
* [[K8s]] | * [[K8s]] | ||
|valign= | |valign='top'| | ||
* [[K8s/Swiss Knife|K8s » Swiss Knife]] | * [[K8s/Swiss Knife|K8s » Swiss Knife]] | ||
* [[K8s/Ingress|K8s » Ingress]] | * [[K8s/Ingress|K8s » Ingress]] | ||
| Line 54: | Line 197: | ||
* [[K8s/Run|K8s » Run]] | * [[K8s/Run|K8s » Run]] | ||
|valign= | |valign='top'| | ||
|} | |} | ||
Latest revision as of 14:55, 25 January 2026
cat << EXE | sudo bash
apt-get update;echo
apt list -a --upgradable
apt-get install -y pgloader
EXE
|
|||
| |||
Migration
|
Migration | |
|---|---|
cat << DDL | mariadb
CREATE DATABASE IF NOT EXISTS academia;
CREATE USER 'chorke'@'%' IDENTIFIED BY 'sadaqah!';
GRANT ALL PRIVILEGES ON academia.* TO 'chorke'@'%';
FLUSH PRIVILEGES;
DDL
|
cat << DDL | psql
CREATE DATABASE academia;
CREATE USER chorke WITH ENCRYPTED PASSWORD 'sadaqah!';
GRANT ALL PRIVILEGES ON DATABASE academia TO chorke;
ALTER DATABASE academia OWNER TO chorke;
DDL
|
BKP_DATE_N_TIME="$(TZ=UTC-8 date +'%Y-%m-%dT%H%M')"
echo -n password: ;read -s MYSQL_PWD;export MYSQL_PWD; echo
# password: sadaqah!
mariadb -h127.0.0.1 -P3306 -uchorke -Dacademia
mariadb-dump -h127.0.0.1 -P3306 -uchorke -Bacademia > ./academia-${BKP_DATE_N_TIME}.dump
mariadb -h127.0.0.1 -P3306 -uchorke -Dacademia < ./academia-20241010-T1010-ZP0600.dump
| |
cat <<MIG | pgloader -v /dev/stdin
LOAD DATABASE
FROM mysql://chorke:sadaqah!@localhost/academia?useSSL=false
INTO pgsql://chorke:sadaqah!@localhost/academia;
MIG
| |
BKP_DATE_N_TIME="$(TZ=UTC-8 date +'%Y-%m-%dT%H%M')"
echo -n password: ;read -s PGPASSWORD;export PGPASSWORD;echo
# password: sadaqah!
psql -h127.0.0.1 -p5432 -Uchorke -dacademia
pg_dump -h127.0.0.1 -p5432 -Uchorke -dacademia | gzip > academia-${BKP_DATE_N_TIME}.sql.gz
gunzip -c academia-20241010-T1010-ZP0600.sql.gz | psql -h127.0.0.1 -p5432 -Uchorke -dacademia
| |
Playground
|
Playground | |
|---|---|
docker run --rm -it ghcr.io/dimitri/pgloader:latest pgloader -h
docker run --rm -it ghcr.io/dimitri/pgloader:latest pgloader -V
|
pgloader -h
pgloader -V
|
pgloader ./sqlite/academia.db pgsql:///academia
pgloader ./sqlite/academia.db pgsql://chorke:sadaqah!@localhost/academia
| |
pgloader mysql://chorke:sadaqah!@localhost/academia pgsql:///academia
pgloader mysql://chorke:sadaqah!@localhost/academia pgsql://chorke:sadaqah!@localhost/academia
| |
cat <<MIG | pgloader -v /dev/stdin
LOAD DATABASE
FROM mysql://chorke:sadaqah!@localhost/academia?useSSL=false
INTO pgsql://chorke:sadaqah!@localhost/academia
WITH include drop, create tables
ALTER SCHEMA 'academia' RENAME TO 'public';
MIG
|
|
References
|
References | ||
|---|---|---|