In this article, we will learn how to install and use the PostgreSQL module, includingChkpass,Fuzzystrmatch,IsnAndHstoreThe. Module adds different functions to the database, such as management and monitoring tools, new data types, operators, functions and algorithms. We will test the modules that add data types and algorithms. These modules allow the database to have the application logic.
PostgreSQL is called "the most advanced open source database". I have been in foodlets for the past four years. use it on in, and store space data on CSTEP (Center for Study of Science, Technology and Policy. PostgreSQL is a database that won't disappoint me.
Installation Module
Note: My runtime environments are Ubuntu 10.04 and PostgreSQL 8.4.
First installPostgresql-contribPackage and restart the database server, and then checkContribCheck whether the directory contains some available modules:
1 |
sudo apt-get install postgresql-contrib |
2 |
sudo /etc/init.d/postgresql-8.4 restart |
3 |
cd /usr/share/postgresql/8.4/contrib/ |
Then we create a database named module_test:
Then we set the moduleChkpass,Fuzzystrmatch,IsnAndHstoreApplyModule_testDatabase:
1 |
psql -d module_test -f chkpass.sql |
2 |
psql -d module_test -f fuzzystrmatch.sql |
3 |
psql -d module_test -f isn.sql |
4 |
psql -d module_test -f hstore.sql |
Next, let's take a look at how each module is used.
Use chkpass
ChkpassThe module introduces a new data type "chkpass" to store an encrypted field, such as a password. You can see from the SQL below that the string stored in the chkpass field is automatically encrypted:
1 |
CREATE TABLE accounts (username varchar (100), password chkpass); |
2 |
INSERT INTO accounts(username, "password" ) VALUES ( 'user1' , 'pass1' ); |
3 |
INSERT INTO accounts(username, "password" ) VALUES ( 'user2' , 'pass2' ); |
Then we can perform identity authentication through the following SQL:
1 |
SELECT count (*) from accounts where username= 'user1' and password = 'pass1' |
Where=Operator UsedEq (column_name, text)This method is provided by the chkpass module to test whether it is equal. Chkpass uses the Unix crypt () function, so the encryption effect is relatively weak. This function only encrypts the first eight digits of the string, as long as the first eight digits of the same string are considered to be equal. Therefore, it is not recommended to use the chkpass module in the actual production environment. We recommend that you use the pgcrypto module.