PostgreSQL Documentation on High Availability is a great resource to use for learning more about how you can scale your database and make sure you have a fallback that will take over the job if your master database crashes. How to setup a Master server with PostgreSQL In the case of, our amount of read queries are far greater than our writes and the type of horizontal scaling described above would work perfect for us. However for every single page view we need to read the user’s data, the article’s content and so much more, just to render the page you’re looking at. Every time an article is created, a comment is posted or a user signs up, we need to write this data to the database. But generally an application will need to accept far more read queries than write queries. Sounds like a lot of work for the master, and for some applications it is. This means that every single INSERT, UPDATE, DELETE, CREATE, ALTER query goes to a single database instance, but every SELECT query will be split among all of your databases. The most common type is where you have a single write instance (master), and an X number of replicas (slaves) that only accept read-queries. Now with that said, there are different types of horizontal scaling and depending on your read/write ratio different types of scaling might have a different impact on your business. In theory, there is no limit of how much you can keep growing. Unlike vertical scaling, with horizontal scaling you can just keep scaling and scaling and scaling. You could have 2 databases, 10, 100 or 1000’nds. Horizontal scaling means that instead of only making a single instance larger and more powerful, we scale our system by adding more instances that work side by side with each other. That’s where horizontal scaling comes in, and that’s what we’ll talk about today. If your single database instance goes down, so does your whole website. We don’t have infinite amount of processing power or memory for a single machine and if you keep growing and keep receiving more and more users, vertical scaling will at some point not work anymore.Ī second downside with vertical scaling is that you have a single-point-of-failure within your infrastructure. The problem with this though is that there’s a limit to how much you can scale a single database server. You just “upgrade your server” and pay more money for it. This could work quite well for some applications since it’s such an easy thing to do. Vertical scaling is when you keep upgrading your existing server and you scale it by making it more and more powerful. But soon enough you’ll need to change the actual infrastructure. So what do you do when you’re starting having database performance issues? You might first attempt to optimize your database queries, add the correct indexes and maybe even reduce joins by changing table structure. But in my own experience, it’s almost always the database that starts to slow down first. Of course every application is different and might have different needs and because of this, there might be other things within your specific application that you need to work on. Most websites out there perform fine by simply having a web server instance and a database server instance, but if you are one of the lucky few who manage to get real traction to your business and start attracting serious number of visitors, you’ll quite quickly run into your first bottleneck, your database. Coderbook How to replicate PostgreSQL Database as Master/Slave
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |