Trending February 2024 # Guide To The Working Of Postgresql Replication # Suggested March 2024 # Top 8 Popular

You are reading the article Guide To The Working Of Postgresql Replication updated in February 2024 on the website Tai-facebook.edu.vn. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested March 2024 Guide To The Working Of Postgresql Replication

Introduction to PostgreSQL Replication

It is necessary to implement various strategies to maintain the high availability of the PostgreSQL database and achieve load balancing in scenarios with a large number of users. One such strategy is utilizing multiple database servers collaborating to serve the users effectively. In this case, it is very easy to provide this facility if all the operations are read-only, which means no operation is performed on the data present in the database servers; only the available data is retrieved. In this topic, we are going to learn about PostgreSQL Replication.

Start Your Free Data Science Course

But in the case of reading/write, servers that involve all kinds of manipulations on the database’s data becomes difficult. This is because a single change in one database should be reflected in all the database servers that are serving the users. In this scenario, data replication is utilized to duplicate or replicate data across multiple database servers. It involves making the same change in all the database servers with which the server is operating, ensuring high availability for the end-users.

Working on PostgreSQL Replication

In PostgreSQL, typically, there is one database server that handles all modification-related operations and requests. Other database servers, commonly referred to as slave servers or standby database servers, then replicate or propagate these changes. That means the master nodes are always the replicated data’s senders, while slave nodes receive the replicated data and apply the same changes over there.

PostgreSQL provides a built-in replication feature known as streaming replication, which operates on a master-slave architecture. When utilizing cascading, both the slave or standby database servers have the capability to send and receive replicated data to and from the master database server.

The slave of standby servers always keep track of the changes made by the master server and tries to keep themselves updated. There are two types of standby database servers, namely hot and warm standby servers. Warm servers are servers that require promotion to the master server role before they can accept user connections. On the other hand, hot standby servers are capable of accepting user connections and performing read-only operations.

The streaming replication system in PostgreSQL utilizes the Write-Ahead Log (WAL) file logging system. This system marks a transaction as committed before applying the corresponding change to the target database. However, this difference is minimal; hence there is no inconsistency between the main and replicated database values.

Settings

In the upcoming sections of this article, we will discuss the settings that need to be configured on each of the master, slave, or sending users.

Sending database servers 1. max_wal_senders(integer)

The maximum number of allowed connections with other slave database servers at a single instance can be specified by this parameter. The parameter’s default value is zero, indicating the absence of replication support and disallowing replicated database connections. This value cannot exceed max_connections as this value is equivalent to the number of current wal connections.

2. wal_keep_segments(integer)

The standby servers require 16-megabytes of past log files stored in the pg_xlog directory for streaming replication in Postgres. The minimum number of segments required by the standby servers for proper replication can be specified by this parameter. You can set its value either from the server command line prompt or the chúng tôi configuration file of PostgreSQL.

3. replication_timeout(integer)

If the standby servers crash or if some network issues occur, the connection to that server must terminate. The server command line prompt or the chúng tôi configuration file of PostgreSQL is where you can modify this parameter. The connection will be terminated if no response is received within a specified time span. The default value for this parameter is 60 seconds.

Master database servers

You should configure the mentioned parameters on the server that serves as the master node or primary node. Additionally, you can also set these parameters on standby servers that may be promoted to the master role in the future.

1. synchronous_standby_names( string )

During replication, there are two modes available: synchronous and asynchronous. In synchronous replication, all participating servers in the replication process must confirm the data modification before it is considered committed. This ensures data consistency across all database servers. On the other hand, asynchronous replication may introduce a slight time difference between the transaction’s commitment and the actual changes being made in the target databases. This can occasionally result in stale results. The “synchronous_standby_names” parameter stores a comma-separated list of standby database servers that support synchronous replication.

2. vacuum_defer_cleanup_age( integer ) Slave/Standby database servers

You should configure the mentioned settings on the slave or standby database servers intended to receive the replicated data.

1. hot_standby(boolean)

The default value of this parameter is set to false. It determines whether it is permissible to establish connections and execute queries while data recovery is in progress.

2. max_standby_archive_delay( integer )

The default value for this parameter is 30 seconds. In the context of hot standby servers, PostgreSQL’s streaming replication feature specifies a duration to wait before canceling queries from standby servers. The wait time is crucial for preventing potential conflicts with upcoming Write-Ahead Log (WAL) entries that are about to be applied.

In addition to the above, three more settings must be configured on the slave server: max_standby_streaming_delay, wal_receiver_status_interval, and hot_standby_feedback.

Conclusion- PostgreSQL Replication

We can provide high-availability and balance the load on the database server by maintaining multiple database servers that can work together and implement replication to serve a large number of users without affecting the performance much in the PostgreSQL database. When performing replication, it is crucial to exercise caution and ensure that all settings are properly configured for the respective database servers based on the role they will fulfill in replication and request handling.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL Replication” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading Guide To The Working Of Postgresql Replication

Learn How To Use The Postgresql Position()

Introduction to PostgreSQL POSITION()

As we know PostgreSQL supports various data types like string, if we are working with string we might need to manipulate the string data, there are various functions to work with the string-like we might have to find the substring of any string. The PostgreSQL POSITION function is used to find the location or position of the substring within a string. By using the position function we can easily find the location of string-like if we have a string “PostgreSQL is awesome” and we wanted to find the location of the substring “awesome” inside the string.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Consider the following syntax of the POSITION() function:

SELECT POSITION([SUBSTRING] IN [string]);

Explanation:

[SUBSTRING]: The input string is a substring to search from a string.

[string]: The string from which we want to search a substring.

How does PostgreSQL Position() function work?

One(1) is the first position in the string.

If the POSITION function cannot find the substring within the string, the position function will return the position as zero(0).

Consider the following example to understand the working of the PostgreSQL Position function.

SELECT POSITION('is' IN 'PostgreSQL is awesome') AS position_of_is

The above syntax creates a temporary variable of name position_of_is containing a number. In our case, this number is 12 because the string is “PostgreSQL is awesome,” the first string position returned by the PostgreSQL POSITION function is at character number 12, which will be stored in the position_of_is temporary variable.

Illustrate the result of the above statement by using the following snapshot.

This function returns us the first position or location of the occurrence of the substring within the string.

Examples to Implement Position() Function in Postgre SQL

We will create tables named ‘category’ to understand the examples of this function in detail.

Consider the following CREATE TABLE statement to create the category table.

CREATE TABLE category ( category_id serial PRIMARY KEY, category_name VARCHAR(80) NOT NULL );

Now, we will insert some data in the ‘category’ table by using the INSERT TABLE statement:

INSERT INTO category(category_name)values ('furniture'), ('Electronics'), ('Cloths');

Illustrate the result of the above statement by using the following snapshot and SQL statement.

select * from category;

1. Consider the following statement, which finds the substring’ n’ position in the column ‘category_name’. 

SELECT category_id, category_name, POSITION('n' IN "category_name") FROM category;

Illustrate the result of the above statement by using the following snapshot.

2. Consider the string ‘PostgreSQL is awesome’ from which we will find out the position of the ‘awesome’ using the PostgreSQL POSITION function.

SELECT POSITION('awesome' IN 'PostgreSQL is awesome');

Illustrate the result of the above statement by using the following snapshot.

3. Consider the following example to understand the case sensitivity.

SELECT POSITION('AWESOME' IN 'PostgreSQL is awesome');

Here we can see that the result of position is zero (0), which means that the string AWESOME does not exist in the string ‘PostgreSQL is awesome’.

4. Consider the following example to understand if the string occurs multiple times.

SELECT POSITION('is' IN 'This is a PostgreSQL');

Illustrate the result of the above statement by using the following snapshot.

Here you can find the substring ‘is’ appears multiple times in the input string ‘This is a PostgreSQL.’

Advantages of using the Position() function in PostgreSQL

The POSITION() function considers a string character case while searching for a substring which means it is case sensitive.s

This function always returns the first instance of occurrence.

We can find the required string position within a table row using the POSITION function.

Conclusion

From the above article, we hope you understand how to use this function and how the POSITION() function works. Also, we have added several examples of the POSITION() function to understand it in detail.

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL POSITION()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

A Guide To Photography Nfts And The Future Of Imagery

Never before has society been so visually saturated. Trillions of photos are taken every year, and the popularity of social media and the prevalence of image-based marketing are simply a given at this point. Clearly, image is everything. But, this proliferation of images and the infrastructure surrounding their consumption hasn’t always been for the better. 

At times, social media has been a particularly fertile ground for the outright plagiarism of professional photographers’ work. In October 2023, photographer Cath Simard shared a picture of a Hawaiian road on her Instagram account. It immediately went viral and was shared across several platforms thousands of times without attribution or compensation. 

Simard turned to NFTs for a solution. Instead of tracking down companies using her image without consent and engaging in costly legal procedures, she minted the photo as an NFT on the Ethereum blockchain, establishing its provenance and immutability. She then released the rights to the image after selling it for 100 ETH ($303,481 at the time). 

Photography and NFTs were made for each other. Not only do they offer an answer to the question of what it means to own an image in online spaces, but they can also provide the artist behind the lens a direct means to earn a living and the opportunity to explore their artistry on their terms. Whether you’ve been into NFTs for a while or are starting to learn about this strange, crypto-adjacent technology, this guide will help you break down everything you need to know about photography NFTs. 

What exactly are photography NFTs? 

If you’re new to NFTs, check out our NFT 101 guide here to get familiar with the basics. Briefly, NFTs are non-fungible digital items (tokens) that are specifically identifiable and unique, like a 1/1 physical painting. The digital token’s identity and existence are immutably recorded onto the blockchain, the web infrastructure they depend on. 

These unique tokens can contain just about any kind of information, including visual information. This is why NFTs so often take the form of visual art; creatives have found this particular NFT use case extremely valuable to their careers and the health of the art industry. 

A photography NFT falls under this visual NFT category. Just as a photographer might print out one of their images, sign it, and sell it, they can utilize blockchain technology to do the same in the digital world. Instead of printing, they can “mint” their work onto the blockchain (a way to officially establish its provenance digitally).

The NFT contains their digital signature, and they can sell that uniquely identifiable photograph to whoever wants it on a digital marketplace. They can even earn royalties on future transactions if the person who bought it decides to sell or trade it to someone else. 

Types of photography NFTs

Like most NFTs, there are various kinds of photography NFTs that artists create and collectors can buy. These include:

A collection: NFT collections are generally composed of several individual pieces of artwork and can range in quantity from anything above two or three pieces to as many as an artist decides they want to include, potentially dozens, hundreds, or more. Justin Aversano’s well-known NFT collection Twin Flames is one example of this, consisting of 100 pieces. 

1/1 NFT: A one-of-one NFT is a singular piece of an artist’s work. These tend to be the most highly valued in an artist’s collection as they are the digital equivalent of single-edition paintings or other physical art.

Open edition: Open edition NFTs are NFTs that are available for collectors to buy for (generally) a specified period set by the artist, usually 24, 48, or 72 hours. They have no cap on their supply. Isaac “Drift” Wright’s First Day Out NFT is an example of this. He sold 10,351 pieces for 0.2 ETH each, with 15 percent of the proceeds going to The Bail Project.

Limited edition: Unlike the open edition, this kind of NFT release has a finite supply and often no time limit. Once their predetermined limit is met, they can no longer be collected. 

How and where to buy photography NFTs

If you’re ready to dive into the world of photography NFTs, here’s how to get started. The first thing you need to do to purchase any NFT is to get a crypto wallet set up. After that, you’ll need to buy some cryptocurrency, which you can easily purchase from an exchange. Once you’ve got some crypto in your wallet, you get to the fun part: shopping around on NFT marketplaces to find something you like.

When you do, you’ll have to check the NFT’s listing details to see if someone has already bought it. If they haven’t and you meet the price requirement, it’s all yours. If someone already owns it, you’ll almost always have the option to put in an offer on it and see if the owner is willing to part with it. 

You can find photography NFTs on almost any Web3 marketplace, but some exist explicitly dedicated to photographs. Quantum Art is one of the most well-known and respected. While the platform also has a section devoted to curated digital art, photographers can submit their work to be accepted into its primary photography division. Ephimera is another platform aimed exclusively at tokenized photography and video. 

Web3 mainstays like OpenSea, Rarible, KnownOrigin, and others generally feature photography NFT collections instead of 1/1 pieces, though you can certainly find them on those platforms as well. Photographers tend to mint their 1/1s on platforms like SuperRare, MakersPlace, Foundation, and Nifty Gateway for those looking for something a little rarer. 

Artists driving Web3 photography forward

While countless photographers use NFTs to further their artistry and the Web3 space, several have made names for themselves in recent months and years for helping shape the NFT ecosystem in important ways. Here are a few to look out for:

Cath Simard

As mentioned earlier, Simard has done wonders for the composite photography medium, and her documentation of the most breathtaking natural landscapes the planet has to offer is truly something to behold. Her collections and limited edition drops and auctions quickly sell out, and her work has been auctioned at Sotheby’s, Nifty Gateway, and more.  

Credit: Cath Simard

Drift

Also known as DrifterShoots, Drift (Isaac Wright) is an Army Special Operations Veteran who turned to scaling bridges and skyscrapers as a way to help him cope with PTSD after he was honorably discharged in March 2023. Known for his vertigo-inducing shots, Drift’s body of work tells the story of someone literally climbing out of depression through their artistry. The nature of his photography led to his being arrested and charged with burglary and trespassing for illegally climbing public structures in Cincinnati, Ohio. Authorities held him in 23-hour lockdown for more than two months after the arrest.

Drift was one of the first artists in the NFT space to successfully experiment with Open Edition releases when he dropped First Day Out in April 2023, a work honoring the one-year anniversary of his release from jail. His NFT project Where My Vans Go is a 125-piece collection of breathtaking and iconic photos taken throughout the United States over a three-year period. The collection has done 4,507 ETH (over $7 million) in trading volume on the secondary market and remains one of the most well-known and beloved collections in the whole of the NFT ecosystem.

Credit: Drift

Justin Aversano

No NFT photography list would be complete without Aversano, whose collections have generated millions of dollars in trading volume and have helped show Web3 exactly what photography is capable of in the NFT ecosystem. Some of his collections include the previously mentioned Twin Flames (a project he created in honor of his twin who died in utero), Smoke and Mirrors, and Every Day is a Gift. Aversano is also the co-founder and creative director of the non-profit SaveArtSpace, a non-profit organization committed to bringing art to community spaces. 

Credit: Justin Aversano Credit: Justin Aversano

Guido Di Salle

Guido Di Salle is one of the biggest names in the NFT ecosystem. A self-described provocateur, Di Salle’s work is reminiscent of the fashion magazines of the 80s and 90s and often depicts sensual, abstract, and viscerally bold imagery. He has made several notable sales in the NFT space of 50 ETH ($150,000) and above, and his work has been featured in GQ Italia and Playboy. 

Credit: Guido Di Salle

Misan Harriman

Social activist and photographer Misan Harriman is well-known for his photographs of the Black Lives Matter movement and for being the first black man to shoot a cover for Vogue UK in the magazine’s 104-year history. Similarly known for his body of work of celebrities ranging from Jay-Z, Tom Cruise, Meghan Markle, and Prince Harry, Harimann’s work has been featured in Harpers Bazaar, Vogue UK, People Magazine, The Telegraph, and more. A believer in the revolutionary potential of Web3, Harriman is the founder of Culture3, an organization dedicated to educating people about the empowering nature of the blockchain for artists and collectors. 

Credit: Misan Harriman

Brayden Hall

Credit: Brayden Hall Credit: Brayden Hall

Nude art photographers

Credit: Nude Yoga Girl

The good, the bad, and the future of Web3 photography

Much like with other industries, NFTs have opened up possibilities for photographers that were previously unthinkable. Overall, NFTs enable artists to connect directly with their collector base without having to run through intermediaries or gatekeepers and can provide them with revenue streams that better reflect the actual value of their work. 

Likewise, NFTs have enabled artists to lean into work that more directly reflects their creative vision rather than having to tailor their work to commercial clients. “With Web3, I’m able to sell things I never would have sold in Web2,” Hall said in an interview with nft now. 

“A lot of people who were up and coming on Instagram or getting client jobs said, ‘Nope, I’m never doing this again, it’s full-time Web3.’ And then the bear market hit.”

Brayden Hall

The Web3 space isn’t without its drawbacks, however. One of the challenges in the NFT ecosystem is its unpredictability and the fact that it requires individuals to constantly put themselves out into the Web3 world to convince people that their work is worth collecting. 

“For commercial work, it’s less of a show,” Hall explained. “In Web3, you’re trying to market yourself to collectors. With commercial work, you pitch a brand, you show them a look-through, and you negotiate a price. You don’t have to explain why you’re the best.”

One of the things that Hall warns new photographers against is devoting the entirety of their efforts to Web3, assuming that it’s going to immediately replace other kinds of work, like client-based jobs or managing their personal brand on social media. 

“Paired with commercial work, it’s actually really awesome,” Hall continued. “There’s no point in giving up on that, but a lot of people have thrown that away. A lot of people who were up and coming on Instagram or getting client jobs said, ‘Nope, I’m never doing this again, it’s full-time Web3.’ And then the bear market hit.” 

“Web3 has a tendency to focus solely on who has collected what and at what price.”

Guido Di Salle

And while there are fewer gatekeepers in Web3 compared to the world of fine art photography, for example, the NFT world still has shades of hierarchy and cults of personality. 

“We have definitely seen gatekeeping within the [NFT] space,” Di Salle lamented while speaking to the differences between the traditional art world and Web3 for photographers. “In Web3, it lies with the tastemakers, or should I say, lack of tastemakers. These individuals can make or break an artist. It is rare that an artist who isn’t in the favorable light of these tastemakers actually breaks through.”

“I’ve lived this firsthand,” he continued. “Web3 has a tendency to focus solely on who has collected what and at what price, and this is very different than the traditional art world I am familiar with. The space also moves more in a herd-type mentality, and although traditional art is guilty of that as well, it’s much more prevalent here.”

For photographers thinking about coming into Web3, Di Salle emphasized that coming into NFTs in a thoughtful manner is crucial to crafting long-term success in the space. 

“To be successful, you need to build a community,” Di Salle continued. “Plans can be fluid, but you can’t just ride in and shoot from the hip. The space is very saturated as well, so you need to carve out your niche. […] It isn’t easy, but if you start with reasonable expectations and work around the clock at it, you could be rewarded.”

“There is no boundary to what’s possible now.”

Chad Torkelsen

Despite its challenges and drawbacks, Web3 holds tantalizing possibilities for photographers and their work. During last year’s annual NFT NYC, for example, photographer Chad Torkelsen organized Comp Stomp Studios, an independent NFT photo gallery side event featuring over 160 artists and their work. When a financial backer dropped out of the project at the last minute, leaving the entire event in limbo, Torkelsen called a collector he’d met through his Web3 connections who agreed to fund the four-day gallery. 

For Torkelsen, the event’s execution was a poignant representation of everything Web3 can do for artists and photographers. 

“That only happened because of Web3,” Torkelsen underscored of the gallery’s salvation in an interview with nft now. “I didn’t have [enough] money. I was able to call a few of my collectors and make arrangements, and that was all through those Web3 connections. That has changed my approach to everything. There is no boundary to what’s possible now. If you have something exciting that you’re passionate about, the community is there to support you and make it happen. And I think that’s a pretty special thing.” 

Credit: Chad Torkelsen

Torkelsen is organizing Comp Stomp Studios again for this year’s NFT NYC in April, with Hall and fellow photographer Nevin Johnson helping him curate the gallery. The event is just one of many encouraging expressions of how Web3 and the photography world are shaping one another for the better. It’s also a stark example of how community-based endeavors enabled by NFTs can do a great deal of good in the world. That’s an image worth appreciating. 

Most Frequently Asked Postgresql Interview Questions

The f

Relational object database.

SQL support and extensibility

API and database validation flexibility.

MVCC and procedural languages,

WAL and Client-Server.

2. List the various data types supported by PostgreSQL.

The following are some of the new data types added to PostgreSQL:

UUID

Numeric types

Boolean

Character types

Temporal types

Geometric primitives

Arbitrary precision numeric

XML

Arrays, etc.

3. What are PostgreSQL’s tokens?

In PostgreSQL, tokens serve as the building elements of source code. They are comprised of a variety of special character symbols. Tokens are keywords mainly made up of predefined SQL commands and meanings. Commands comprise a sequence of tokens separated by a semicolon (‘;’). These may comprise of a constant, a quoted identifier, additional identifiers, a keyword, or a constant. Typically, Whitespace separates tokens.

4. What are the PostgreSQL Indices?

Indexes are a special PostgreSQL tool used to improve data retrieval from databases. A database index is similar to a book index. An index provides access to all the values in the indexed columns.PostgreSQL indexes let the database server locate and retrieve specific rows contained within a particular framework. B-tree, hash, GiST, SP-GiST, GIN, and BRIN are other examples. In PostgreSQL, users are indeed free to create their own indices. However, indices increase the complexity of data processing operations and are rarely employed.

5. How do I set up a PostgreSQL database?

There are two ways to generate databases. The CREATE DATABASE SQL command comes first.

Using the following syntax, we may build the database:-CREATE DATABASE ;

The second approach makes use of the createdb command.

We could establish the database with the following syntax:- createdb [option…] [description].

Depending on the use scenario, the createDB command may take many arguments.

6. How you can create a table in PostgreSQL?

You may create a new table by defining the table’s name, along with the names and types of each column:

CREATE TABLE [IF NOT EXISTS] table_name ( column1 datatype(length) column_contraint, column2 datatype(length) column_contraint, . . . columnn datatype(length) column_contraint, table_constraints );

7. Contrast ‘PostgreSQL’ to ‘MongoDB’

PostgreSQL is a SQL database in which data is stored in rows and columns of tables. It supports notions like entity-relationship integrity and JOINS. The PostgreSQL querying language is SQL. PostgreSQL supports vertical scaling. This necessitates the usage of large servers for data storage. This results in the need for downtime to update. It performs better if your application requires relational databases or if you need to carry out complex queries that exceed the capabilities of chúng tôi contrast, MongoDB is a NoSQL database. There is no necessity for a schema, therefore unstructured data can be stored. Data is saved in BSON documents, the structure of which may be reformed by the user. MongoDB queries are written in JavaScript. As a result of its adaptability for horizontal scaling, extra servers may be added as needed with low to no downtime. A use case that necessitates a highly scalable, distributed database that holds unstructured data is suited for this technology.

8. What is PostgreSQL’s Multi-Version concurrency control?

PostgreSQL uses MVCC, also regarded as Multi-version concurrency control, to implement transactions. It is used to prevent unintended database lockout in the system. Each transaction that queries a database sees a different version of the database. This prevents the display of inconsistent data and provides transaction isolation for each database session. MVCC locks for data reading do not interfere with locks acquired for writing data.

9. What exactly is pgAdmin?

pgAdmin is a Web-based GUI utility for interacting with Postgres database sessions. It is applicable to both local and distant servers. Its most recent release, pgAdmin4, is distributed under the PostgreSQL License. pgAdmin4 creation required a complete rebuild of the original pgAdmin program. This version was made with a mix of Javascript/jQuery and Python. pgAdmin can now be used as a desktop runtime or as a web application server, depending on your needs.

10. How is the database deleted in PostgreSQL?

Using the syntax, databases may be removed in chúng tôi DATABASE [IF EXISTS] ;

Please note that only inactive databases can be discarded.

11. What does a schema consist of?

Schemas are elements of databases, including tables. They include data types, functions, and operators, among other named object types. The object names are compatible across schemas; unlike databases, schemas are divided more freely. This indicates that a user can access objects in any of the schemas in the database they are linked to until they are granted the appropriate permissions. Schemas are incredibly beneficial when several users must access a single database without interfering with one another. It facilitates the organization of database items into logical categories for better management. To prevent name-based conflicts, third-party applications could be placed in distinct schemas.

12. What are the most significant differences between SQL and PostgreSQL?

PostgreSQL is a sophisticated SQL variant. PostgreSQL views cannot be updated.PostgreSQL does not support calculated columns. However, it does provide functional indexes. In PostgreSQL, replication takes the form of reports. PostgreSQL provides actions that are dynamic.

The PostgreSQL server provides several levels of encryption and flexibility to improve data security from disclosure in an insecure network scenario. Meanwhile, the SQL server is designed to provide a safe database platform. To that end, it includes several capabilities that can encrypt data, decrease authorization, and protect data from unethical acts.

13. Explain Write-Ahead Logging in detail.

Write-ahead logging (WAL) is vital to Postgres’ durability and data consistency. All modifications are initially captured to this append-only log, then to the data files on disk. Using write-ahead logging, you can protect your data against corruption. As a result of this method, a complete record of all operations and alterations is maintained. It’s well-known that backing up database changes before implementing or updating them improves the stability of certain databases. A backup log is kept here in case the database fails. When Postgres enforces write operations, it creates WAL (e.g., INSERT, UPDATE, etc.). In situations when WAL creation exceeds the capability of WAL archival off-disk or where a high database load reduces archiver performance, WAL capacity is limited.

14. What is the definition of a non-clustered index?

A non-clustered index in PostgreSQL is a simple index used to quickly retrieve data with no assurance of uniqueness. It includes references to other places where data is kept. This is known as a secondary index too. You can have several indices of this category as you want on a given table. Non-clustered indexes are analogous to a document’s “Table of Contents.” We check the page number first, then the page numbers after that to view the entire content. It keeps a pointer to corresponding heap data to get the whole data based on an index. It’s exactly similar to knowing the page number and then going to that page to retrieve the actual content of the page.

15. How does PostgreSQL provide security?

PostgreSQL employs two tiers of security.

Network-level security- Utilization of Unix Domain sockets, TCP/IP sockets, and firewalls for network-level security.

Transport-level security- Transport-level security employs SSL/TLS to ensure the safe database communication

Database-level security- Roles and permissions, row-level security (RLS), and auditing are all characteristics of database-level security.

Conclusion

In this article, we have seen important PostgreSQL questions. We got a good understanding of different PostgreSQL terminologies. Below are some major takeaways from the above article:

1. We have seen PostgreSQL’s tokens and what are the benefits of using PostgreSQL.

2. We learned about How to set up a PostgreSQL database?

3. We got an understanding of how we can create a table in PostgreSQL?

And much more.

The media shown in this article is not owned by Analytics Vidhya and is used at the Author’s discretion.

Working Of Substr() Function In C++

Introduction to C++ Substring

In C++, a substring refers to a part of a string. To retrieve a substring from a given string in C++, the substr() function is used. It takes the two parameters position and length, where position represents the starting position of the substring in the given string, and length represents the number of characters in the substring to be retrieved from the given string. This substr() function returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length.

Start Your Free Software Development Course

Syntax:

substr(position, length)

Where “position” represents the starting position of the substring in the given string, and “length” represents the number of characters in the substring to retrieve from the given string.

Working of Substr() Function in C++

Working of substr() function in C++ is as follows:

In C++, we use the substr() function to retrieve a substring from a given string. A substring in C++ refers to a part of the string.

The substr() function takes two parameters: position and length.

The parameter position represents the starting position of the substring in the given string.

The parameter length represents the number of characters in the substring to retrieve from the given string.

The substr() function returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length.

Examples of C++ Substring

Following are the examples:

Example #1

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = "Welcome to C++_learning"; string strtwo = strone.substr(11, 12); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

In the above program, we have included the headers iostream and string, allowing us to use cin, court, and substr. The program executes the primary method and defines a string variable, “strone,” to store the original string from which a substring will be extracted. Using the substr function, the program extracts a substring from the string “strone,” starting from a specified position and extending for a specified length. The resulting substring is stored in the string variable “strtwo.” Finally, the program displays the extracted substring, which is stored in the variable “strtwo,” as the output on the screen.

Example #2

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = " EDUCBA is the best site for learning"; string strtwo = strone.substr(0, 6); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

Example #3

C++ program to demonstrate substr function that returns the substring extracted from the given string starting from the specified position up to the number of characters from the starting position specified as length:

Code:

using namespace std; int main() { string strone = " Learning is fun"; string strtwo = strone.substr(12, 3); cout << "The given string is: " << strone << "n" <<endl; cout << "The substring extracted from the given string is: " << strtwo << "n" << endl; return 0; }

Output:

In the above program, we have included the headers iostream and string, allowing us to use cin, court, and substr. The program calls the main method and defines a string variable called “strone” to store the original string. The program then uses the substr function to extract a substring from the string “strone” starting from a specified position and extending for a specified length. It stores the resulting substring in the string variable “strtwo.” Finally, the program displays the extracted substring, which is stored in the variable “strtwo,” as the output on the screen.

Recommended Articles

We hope that this EDUCBA information on “C++ Substring” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Working And Examples Of Typescript Enum

Introduction to TypeScript enum

The new data type supported in TypeScript is called enumerations or enum using which lets us declare names which means a collection of related values which can be either string or numeric, and there are three types of enums in TypeScript, namely Numeric enum, string enum and Heterogeneous enum where numeric enum are the enums based on numbers that are they store numbers in the form of the string, string enum is the enums based on strings that is they store string values, heterogeneous enum are the enums based on both strings and numbers that is they store both string and numeric values.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

enum enum_name{ enum_value1, enum_value2, .. Enum_valuen }

where enum_name represents the name of the enum,

enum_value1, enum_value2, and enum_valuen represent the collection of related values, either string or numeric.

Working of enum in TypeScript

The new data type supported in TypeScript is called enumerations or enum using which lets us declare names which means a collection of related values that can be either string or numeric.

The keyword enum is used to define enum in TypeScript.

There are three types of enum in TypeScript, namely Numeric enum, string enum, and Heterogeneous enum.

Numeric enum is the enums based on numbers; they store numbers in the form of strings.

The enum values for numeric enum begin from zero and increase by one for each number.

There is also an option to initialize the first enum value ourselves in a numeric enum, and the rest of the values would be increased by one.

The enum values do not have to be in sequence in the numeric enum.

String enum is the enums based on strings that is they store string values.

The readability of the program increases by using a string enum.

Heterogeneous enum is the enums based on both strings and numbers; they store both string and numeric values.

Examples of TypeScript enum

Different examples are mentioned below:

Example #1

TypeScript program to demonstrate the usage of numeric enum that initializes values and are displayed as the output on the screen:

Code:

enum Country { India, USA, Germany, London } console.log("The values initialized by enum is as follows:"); console.log(Country.India); console.log(Country.USA); console.log(Country.Germany); console.log(Country.London);

Output:

In the above program, by using the keyword enum, we define a numeric enum whose values are initialized starting from zero and incremented by one for each member. Then the initialized values for the numeric enum are displayed as the output on the screen.

Example #2

TypeScript program to demonstrate the usage of numeric enum that initializes values where the first value is initialized by ourselves and are displayed as the output on the screen:

Code:

enum Country { India = 5, USA, Germany, London } console.log("The values initialized by enum is as follows:"); console.log(Country.India); console.log(Country.USA); console.log(Country.Germany); console.log(Country.London);

Output:

In the above program, by making use of the keyword enum, we are defining a numeric enum in which the first value is initialized as five by ourselves and then incremented by one for each member. Then the initialized values for the numeric enum are displayed as the output on the screen.

Example #3

TypeScript program to demonstrate the usage of string enum that initializes string values and are displayed as the output on the screen:

Code:

enum Capital { India = 'New Delhi', USA = 'Washington', Germany = 'Berlin', England = 'London' } console.log("The values initialized by string enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

Output:

In the above program, by using the keyword enum, we define a string enum whose values are initialized to certain string values. Then the initialized values for the string enum is displayed as the output on the screen.

Example #4

TypeScript program to demonstrate the usage of heterogeneous enum that initializes both string values and numeric values and are displayed as the output on the screen:

Code:

enum Capital { India = 1, USA = 'Washington', Germany = 3, England = 'London' } console.log("The values initialized by heterogeneous enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

In the above program, by using the keyword enum, we define a heterogeneous enum whose values are initialized to certain string values and certain numeric values. Then the initialized values for the heterogeneous enum is displayed as the output on the screen.

Example #5

TypeScript program to demonstrate the usage of heterogeneous enum that initializes both string values and numeric values and are displayed as the output on the screen:

Code:

enum Capital { India = 8, USA = 12, Germany = 'Berlin', England = 'London' } console.log("The values initialized by heterogeneous enum is as follows:"); console.log(Capital.India); console.log(Capital.USA); console.log(Capital.Germany); console.log(Capital.England);

Output:

In the above program, by using the keyword enum, we define a heterogeneous enum whose values are initialized to certain string values and certain numeric values. Then the initialized values for the heterogeneous enum is displayed as the output on the screen.

Recommended Articles

We hope that this EDUCBA information on “TypeScript enum” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Update the detailed information about Guide To The Working Of Postgresql Replication on the Tai-facebook.edu.vn website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!