Saturday, September 3, 2022
HomeWordPress DevelopmentMigrating Your PostgreSQL Database From Heroku to CockroachDB

Migrating Your PostgreSQL Database From Heroku to CockroachDB


After virtually a decade, Heroku introduced that they’ll get rid of all of their free tier companies. They will additionally delete inactive accounts and related storage with these accounts which have been inactive for over a 12 months. Of their weblog put up, they blamed ‘abuse’ for his or her demise of free companies.

Quoted from the TechCrunch article,

In a weblog put up, Bob Smart, Heroku common supervisor and Salesforce EVP, blamed ‘abuse’ on the demise of the free companies, which span the free plans for Heroku Dynos and Heroku Postgres in addition to the free plan for Heroku Information for Redis. ‘Our product, engineering, and safety groups are spending a rare quantity of effort to handle fraud and abuse of the Heroku free product plans,’ Smart stated. ‘We are going to proceed to supply low-cost options for compute and information assets.’

Smart went on to notice that Heroku shall be saying a pupil program at Salesforce’s upcoming Dreamforce convention in September, however the particulars stay a thriller at this level.

That is huge information: Heroku was one of many best methods so that you can get a free server, PostgreSQL database, and a Redis cache, all in a single location and all free of charge.

Nonetheless, ranging from 28 November this 12 months, all of these free companies are going away.

What does this imply? Properly, with my cursory data of startups, free tiers largely solely exist to encourage progress, and if the platform is not rising, then there merely is not a lot level in having a free tier as corporations would simply lose cash from them.

With that being stated, this forces us builders emigrate from Heroku or pay a minimal of $25 a month. Even worse, if you wish to run PostgreSQL, you may need to pay $50 each single month!



Migrating Away From Heroku

I do not find out about you, however I haven’t got that a lot cash to throw round. Nonetheless, if you happen to use Heroku, don’t fret! Loads of platforms nonetheless have free tiers. For example, you should use Netlify or Vercel free of charge internet hosting and superior edge features, Upstash for serverless Redis, and CockroachDB for a serverless and distributed PostgreSQL database!

CockroachDB is suitable with the PostgreSQL ecosystem, which means that migrating will not be laborious in any respect. Though, it does have options for importing MySQL dump recordsdata, if you happen to’re seeking to swap over from different platforms. Behind the scenes, your information is replicated at the least 3 instances – and you will not face downtime for issues like zone outages, database upgrades, and safety patches. Even schema modifications are on-line! Additionally, CockroachDB is a distributed database, the place you’ll be able to retailer information closest to your customers. Mix this with Vercel/Deno/Netlify edge features, and also you get actually quick and dependable database entry on the edge.

It is not simply wonderful, it is low-cost too. It has a very beneficiant free tier the place you recover from 5GB storage and over 250M request items per 30 days – an absolute steal! If it is advisable scale additional, it is solely $1 for each further GB of storage you employ, and solely $1 for 10M request items. You possibly can even set ‘spend limits’ which is used to control your use of request items and storage.



Migrating Your Database From Heroku PostgreSQL

Let’s transfer onto really migrating our database away from PostgreSQL and onto CockroachDB!

There is a utility in PostgreSQL referred to as pg_dump, which is used for making a backup of the database. This solely backs up a single database, and you should use pg_dumpall to again up world objects which can be widespread to all databases in a cluster (akin to roles and tablespaces).

So, let’s go into our terminal and run a command. I am utilizing Arch Linux, which has an superior PostgreSQL package deal, nonetheless if you happen to’re on Home windows chances are you’ll run into some errors attempting to run this command. In case you’ve gotten the same problem, I counsel you check with this Stack Overflow query.

Anyhow, if you happen to’ve put in and configured PostgreSQL already, you’ll be able to simply run:

pg_dump --host=host.ec2.compute-1.amazonaws.com --port=5432 --username=your_username --password --dbname=database_name > db.sql
Enter fullscreen mode

Exit fullscreen mode

It’s going to immediate you to your password, simply enter that in, and you must have a db.sql file with generated tables – superior!



Import Onto CockroachDB

Now that we have now a backup, let’s import it onto CockroachDB.

If you have not already, you’ll be able to join a free CockroachDB serverless account at cockroachlabs.cloud. No bank card required!

After that, you’ll be able to simply create a brand new cluster and configure it to your wants. I would counsel maintaining AWS because the cloud supplier, and choosing the area geographically closest to you or nearly all of your customers. I will additionally change my cluster title to one thing I like.

A brand new cluster shall be created inside ~5 seconds, and you then’ll need to create a brand new SQL person with a password. Afterwards, it’s going to provide you with directions on how to hook up with it as effectively! You will have to start by downloading the CA certificates, and after that your database needs to be good to go!

As for importing our information onto CockroachDB, we have now two choices: we are able to both use the IMPORT PGDUMP assertion (documentation), or we might use the IMPORT assertion which permits us emigrate native PostgreSQL and MySQL dump recordsdata onto CockroachDB!

We’ll be going with the latter, because the IMPORT PGDUMP assertion requires you so as to add a billing technique, and it is primarily for databases hosted on the cloud.

Copy paste your connection string from the modal, and run the next perform:

cockroach import db pgdump db.sql --url "postgresql://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]" --ignore-unsupported-statements
Enter fullscreen mode

Exit fullscreen mode

Ensure that to move within the ignore-unsupported-statements flag on the finish because it ignores SQL statements within the dump file which can be unsupported by CockroachDB.

You may also move in an additional parameter, log_ignored_statements, for logging unsupported statements when utilizing ignore_unsupported_statements to a specified vacation spot. You might also must take away sure statements in your dump file if you happen to’re having points.

Anyhow, with that, you must get the message ‘efficiently imported pgdump file db.sql‘.

Superior, we have completed it – you’ll be able to merely substitute in your Heroku Database URL with the brand new one from CockroachDB, and the whole lot ought to work as anticipated!



Conclusion

…and that is it! We migrated our whole database from Heroku’s PostgreSQL onto CockroachDB serverless. We have not solely migrated our database, however upgraded it as effectively 😛 – there’s merely no comparability between the 2!

Anyhow, that wraps up as we speak’s article. A number of individuals are devastated listening to the information of Heroku ending their free plan, and as a former Heroku person I used to be disillusioned too. I wished to place out this text serving to you all navigate by migrating your PostgreSQL databases from Heroku onto CockroachDB, as the method may get sophisticated at instances. I hope this saved you some effort and time.

That is all for as we speak, till subsequent time 👋.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments