0

psql: FATAL: Ident authentication failed for user "username" Error and Solution

Q. I've installed Postgresql under Red Hat Enterprise Linux 5.x server. I've created username / password and database. But when I try to connect it via PHP or psql using following syntax:
psql -d myDb -U username -W
It gives me an error that read as follows:
psql: FATAL: Ident authentication failed for user "username"
How do I fix this error?

A. To fix this error open PostgreSQL client authentication configuration file /var/lib/pgsql/data/pg_hba.conf :
# vi /var/lib/pgsql/data/pg_hba.conf
This file controls:
  1. Which hosts are allowed to connect
  2. How clients are authenticated
  3. Which PostgreSQL user names they can use
  4. Which databases they can access
By default Postgresql uses IDENT-based authentication. All you have to do is allow username and password based authentication for your network or webserver. IDENT will never allow you to login via -U and -W options. Append following to allow login via localhost only:
local all all trust
host all 127.0.0.1/32 trust
Save and close the file. Restart Postgresql server:
# service postgresql restart
Now, you should able to login using following command:
$ psql -d myDb -U username -W


article source: http://www.cyberciti.biz/faq/psql-fatal-ident-authentication-failed-for-user/ 

0

Regular Expressions in PostgreSQL


Every programmer should embrace and use regular expressions (INCLUDING Database programmers). There are many places where regular expressions can be used to reduce a 20 line piece of code into a 1 liner. Why write 20 lines of code when you can write 1.

Regular expressions are a domain language just like SQL. Just like SQL they are embedded in many places. You have them in your program editor. You see it in sed, grep, perl, PHP, Python, VB.NET, C#, in ASP.NET validators and javascript for checking correctness of input. You have them in PostgreSQL as well where you can use them in SQL statements, domain definitions and check constraints. You can mix regular expressions with SQL. When you mix the two domain languages, you can do enchanting things with a flip of a wrist that would amaze your less informed friends. Embrace the power of domain languages and mix it up. PostgreSQL makes that much easier than any other DBMS we can think of.
For more details on using regular expressions in PostgreSQL, check out the manual pages Pattern Matching in PostgreSQL
The problem with regular expressions is that they are slightly different depending on what language environment you are running them in. Different enough to be frustrating. We'll just focus on their use in PostgreSQL, though these lessons are applicable to other environments.

Common usages

We are going to go backwards a bit. We will start with demonstrations of PostgreSQL SQL statements that find and replace things and list things out with regular expressions. For these exercises we will be using a contrived table called notes, which you can create with the following code.
CREATE TABLE notes(note_id serial primary key, description text); INSERT INTO notes(description) VALUES('John''s email address is johnny@johnnydoessql.com. Priscilla manages the http://www.johnnydoessql.com site. She also manages the site http://jilldoessql.com and can be reached at 345.678.9999 She can be reached at (123) 456-7890 and her email address is prissy@johnnydoessql.com or prissy@jilldoessql.com.'); INSERT INTO notes(description) VALUES('I like ` # marks and other stuff that annoys militantdba@johnnydoessql.com. Militant if you have issues, give someone who gives a damn a call at (999) 666-6666.');

Regular Expressions in PostgreSQL

PostgreSQL has a rich set of functions and operators for working with regular expressions. The ones we commonly use are ~, regexp_replace, and regexp_matches.
We use the PostgreSQL g flag in our use more often than not. The g flag is the greedy flag that returns, replaces all occurrences of the pattern. If you leave the flag out, only the first occurrence is replaced or returned in the regexp_replace, regexp_matches constructs. The ~ operator is like the LIKE statement, but for regular expressions.

Destroying information

The power of databases is not only do they allow you to store/retrieve information quickly, but they allow you to destroy information just as quickly. Every database programmer should be versed in the art of information destruction.
 -- remove email addresses if description has email address 
 UPDATE notes SET description = regexp_replace(description, 
       E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}', 
        '---', 'g') 
        WHERE description 
        ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}'; 
        
 -- remove website urls if description has website urls 
 -- matches things like http://www.something.com or http://something.com

 UPDATE notes SET description = regexp_replace(description, 
       E'http://[[[:alnum:]]+.]*[[:alnum:]]+[.][[:alnum:]]+', 
        E'--', 'g') 
        WHERE description 
        ~ E'http://[[[:alnum:]]+.]*[[:alnum:]]+[.][[:alnum:]]+'; 

-- remove phone numbers if description 
-- has phone numbers e.g. (123) 456-7890 or 456-7890 or 123.456.7890
UPDATE notes SET description = regexp_replace(description, 
      E'[\(]{0,1}[0-9]{3}[\).-]{0,1}[[:space:]]*[0-9]{3}[.-]{0,1}[0-9]{4}',
        '---', 'g') 
        WHERE description 
        ~ E'[\(]{0,1}[0-9]{3}[\).-]{0,1}[[:space:]]*[0-9]{3}[.-]{0,1}[0-9]{4}'; 

-- set anything to single space that is not not a \ ( ) & * /,;. > < space or alpha numeric        
UPDATE notes set description = regexp_replace(description, E'[^\(\)\&\/,;\*\:.\>\<[:space:]a-zA-Z0-9-]', ' ') 
  WHERE description ~ E'[^\(\)\&\/,;\*\:.\<\>[:space:]a-zA-Z0-9-]';
  
-- replace high byte characters with space 
-- this is useful if you have your database in utf8 and you often need to use latin1 encoding
-- and you have a table that shouldn't have high byte characters 
-- such as junk you get from scraping websites
-- high byte characters don't convert down to latin1
UPDATE notes SET description = regexp_replace(description,E'[^\x01-\x7E]', ' ', 'g')
WHERE description ~ E'[^\x01-\x7E]';

Getting list of matches

These examples use similar to our destroy but show us in a table, a list of stuff that match. Here we use our favorite PostgreSQL regexp_matches function.


-- list first email address from each note --
SELECT note_id, 
  (regexp_matches(description, 
    E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'))[1]  As email
FROM notes
WHERE description ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'
ORDER By note_id, email;
-- result
 note_id |             email
---------+-------------------------------
       1 | johnny@johnnydoessql.com
       2 | militantdba@johnnydoessql.com


--list all email addresses
-- note this uses the PostgreSQL 8.4 unnest construct 
-- to convert the array returned to a table
SELECT note_id, 
  unnest(
    regexp_matches(description, 
    E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+', 'g')
  ) As email
FROM notes
WHERE description ~ E'[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]+'
ORDER By note_id, email;

-- returns
 note_id |             email
---------+-------------------------------
       1 | johnny@johnnydoessql.com
       1 | prissy@jilldoessql.com
       1 | prissy@johnnydoessql.com
       2 | militantdba@johnnydoessql.com

Parts of a Regular Expresssion

Here we will just cover what we consider the parts you need to know if you don't have the patience or memory to remember more. Regular expressions are much richer than our simplified view of things. There is the great backreferencing feature we won't get into which allows you to reference an expression and use it as part of your replacement expression.
PartExample
Classes []Regular expression classes are a set of characters that you can treat as interchangeable. They are formed by enclosing the characters in a bracket. They can also have nested classes. For example [A-Za-z] will match any letter between A-Z and a-z. [A-Za-z[:space:]] will match those plus white spaces in PostgreSQL. If you need to match a regular expression character such as ( then you escape it with \. so [A-Za-z\(\)] will match A thru Z a thru z and ( ). Classes can contain other classes and expressions as members.
.The famous . matches any character. So the infamous .* means one or more of anything.
Quantity {} + *You denote quantities with {}, +, * + means 1 or more. * means 0 or more and {} to denote allowed quantity ranges. [A-Za-z]{1,5} means you can have between 1 and 5 alpha characters in and expression for it to be a match.
()This is how you denote a subexpression. A subexpression can be composed of multiple classes etc and can be backreferenced. They define a specific sequence of characters.
[^members here]This is the NOT operator in regular expressions so for example [^A-Za-z] will match any character that is not in the alphabet.
Special classes[[:alnum:]] any alphanumeric, [[:space:]] any white space character. There are others, but those are the most commonly used.


 Article source: http://www.postgresonline.com/journal/index.php?/archives/152-Regular-Expressions-in-PostgreSQL.html

0

The 25 most difficult questions you'll be asked on a job interview

Being prepared is half the battle.

If you are one of those executive types unhappy at your present post and embarking on a New Year's resolution to find a new one, here's a helping hand. The job interview is considered to be the most critical aspect of every expedition that brings you face-to- face with the future boss. One must prepare for it with the same tenacity and quickness as one does for a fencing tournament or a chess match.
This article has been excerpted from "PARTING COMPANY: How to Survive the Loss of a Job and Find Another Successfully" by William J. Morin and James C. Cabrera. Copyright by Drake Beam Morin, inc. Publised by Harcourt Brace Jovanovich.
Morin is chairman and Cabrera is president of New York-based Drake Beam Morin, nation's major outplacement firm, which has opened offices in Philadelphia.

1. Tell me about yourself.

Since this is often the opening question in an interview, be extracareful that you don't run off at the mouth. Keep your answer to a minute or two at most. Cover four topics: early years, education, work history, and recent career experience. Emphasize this last subject. Remember that this is likely to be a warm-up question. Don't waste your best points on it.

2. What do you know about our organization?

You should be able to discuss products or services, revenues, reputation, image, goals, problems, management style, people, history and philosophy. But don't act as if you know everything about the place. Let your answer show that you have taken the time to do some research, but don't overwhelm the interviewer, and make it clear that you wish to learn more.
You might start your answer in this manner: "In my job search, I've investigated a number of companies.
Yours is one of the few that interests me, for these reasons..."
Give your answer a positive tone. Don't say, "Well, everyone tells me that you're in all sorts of trouble, and that's why I'm here", even if that is why you're there.

3. Why do you want to work for us?

The deadliest answer you can give is "Because I like people." What else would you like-animals?
Here, and throughout the interview, a good answer comes from having done your homework so that you can speak in terms of the company's needs. You might say that your research has shown that the company is doing things you would like to be involved with, and that it's doing them in ways that greatly interest you. For example, if the organization is known for strong management, your answer should mention that fact and show that you would like to be a part of that team. If the company places a great deal of emphasis on research and development, emphasize the fact that you want to create new things and that you know this is a place in which such activity is encouraged. If the organization stresses financial controls, your answer should mention a reverence for numbers.
If you feel that you have to concoct an answer to this question - if, for example, the company stresses research, and you feel that you should mention it even though it really doesn't interest you- then you probably should not be taking that interview, because you probably shouldn't be considering a job with that organization.
Your homework should include learning enough about the company to avoid approaching places where you wouldn't be able -or wouldn't want- to function. Since most of us are poor liars, it's difficult to con anyone in an interview. But even if you should succeed at it, your prize is a job you don't really want.

4. What can you do for us that someone else can't?

Here you have every right, and perhaps an obligation, to toot your own horn and be a bit egotistical. Talk about your record of getting things done, and mention specifics from your resume or list of career accomplishments. Say that your skills and interests, combined with this history of getting results, make you valuable. Mention your ability to set priorities, identify problems, and use your experience and energy to solve them.

5. What do you find most attractive about this position? What seems least attractive about it?

List three or four attractive factors of the job, and mention a single, minor, unattractive item.

6. Why should we hire you?

Create your answer by thinking in terms of your ability, your experience, and your energy. (See question 4.)

7. What do you look for in a job?

Keep your answer oriented to opportunities at this organization. Talk about your desire to perform and be recognized for your contributions. Make your answer oriented toward opportunity rather than personal security.

8. Please give me your defintion of [the position for which you are being interviewed].

Keep your answer brief and taskoriented. Think in in terms of responsibilities and accountability. Make sure that you really do understand what the position involves before you attempt an answer. If you are not certain. ask the interviewer; he or she may answer the question for you.

9. How long would it take you to make a meaningful contribution to our firm?

Be realistic. Say that, while you would expect to meet pressing demands and pull your own weight from the first day, it might take six months to a year before you could expect to know the organization and its needs well enough to make a major contribution.

10. How long would you stay with us?

Say that you are interested in a career with the organization, but admit that you would have to continue to feel challenged to remain with any organization. Think in terms of, "As long as we both feel achievement-oriented."

11. Your resume suggests that you may be over-qualified or too experienced for this position. What's Your opinion?

Emphasize your interest in establishing a long-term association with the organization, and say that you assume that if you perform well in his job, new opportunities will open up for you. Mention that a strong company needs a strong staff. Observe that experienced executives are always at a premium. Suggest that since you are so wellqualified, the employer will get a fast return on his investment. Say that a growing, energetic company can never have too much talent.

12. What is your management style?

You should know enough about the company's style to know that your management style will complement it. Possible styles include: task oriented (I'll enjoy problem-solving identifying what's wrong, choosing a solution and implementing it"), results-oriented ("Every management decision I make is determined by how it will affect the bottom line"), or even paternalistic ("I'm committed to taking care of my subordinates and pointing them in the right direction").
A participative style is currently quite popular: an open-door method of managing in which you get things done by motivating people and delegating responsibility.
As you consider this question, think about whether your style will let you work hatppily and effectively within the organization.

13. Are you a good manager? Can you give me some examples? Do you feel that you have top managerial potential?

Keep your answer achievementand ask-oriented. Rely on examples from your career to buttress your argument. Stress your experience and your energy.

14. What do you look for when You hire people?

Think in terms of skills. initiative, and the adaptability to be able to work comfortably and effectively with others. Mention that you like to hire people who appear capable of moving up in the organization.

15. Have you ever had to fire people? What were the reasons, and how did you handle the situation?

Admit that the situation was not easy, but say that it worked out well, both for the company and, you think, for the individual. Show that, like anyone else, you don't enjoy unpleasant tasks but that you can resolve them efficiently and -in the case of firing someone- humanely.

16. What do you think is the most difficult thing about being a manager or executive?

Mention planning, execution, and cost-control. The most difficult task is to motivate and manage employess to get something planned and completed on time and within the budget.

17. What important trends do you see in our industry?

Be prepared with two or three trends that illustrate how well you understand your industry. You might consider technological challenges or opportunities, economic conditions, or even regulatory demands as you collect your thoughts about the direction in which your business is heading.

18. Why are you leaving (did you leave) your present (last) job?

Be brief, to the point, and as honest as you can without hurting yourself. Refer back to the planning phase of your job search. where you considered this topic as you set your reference statements. If you were laid off in an across-the-board cutback, say so; otherwise, indicate that the move was your decision, the result of your action. Do not mention personality conflicts.
The interviewer may spend some time probing you on this issue, particularly if it is clear that you were terminated. The "We agreed to disagree" approach may be useful. Remember hat your references are likely to be checked, so don't concoct a story for an interview.

19. How do you feel about leaving all your benefits to find a new job?

Mention that you are concerned, naturally, but not panicked. You are willing to accept some risk to find the right job for yourself. Don't suggest that security might interest you more than getting the job done successfully.

20. In your current (last) position, what features do (did) you like the most? The least?

Be careful and be positive. Describe more features that you liked than disliked. Don't cite personality problems. If you make your last job sound terrible, an interviewer may wonder why you remained there until now.

21. What do you think of your boss?

Be as positive as you can. A potential boss is likely to wonder if you might talk about him in similar terms at some point in the future.

22. Why aren't you earning more at your age?

Say that this is one reason that you are conducting this job search. Don't be defensive.

23. What do you feel this position should pay?

Salary is a delicate topic. We suggest that you defer tying yourself to a precise figure for as long as you can do so politely. You might say, "I understand that the range for this job is between $______ and $______. That seems appropriate for the job as I understand it." You might answer the question with a question: "Perhaps you can help me on this one. Can you tell me if there is a range for similar jobs in the organization?"
If you are asked the question during an initial screening interview, you might say that you feel you need to know more about the position's responsibilities before you could give a meaningful answer to that question. Here, too, either by asking the interviewer or search executive (if one is involved), or in research done as part of your homework, you can try to find out whether there is a salary grade attached to the job. If there is, and if you can live with it, say that the range seems right to you.
If the interviewer continues to probe, you might say, "You know that I'm making $______ now. Like everyone else, I'd like to improve on that figure, but my major interest is with the job itself." Remember that the act of taking a new job does not, in and of itself, make you worth more money.
If a search firm is involved, your contact there may be able to help with the salary question. He or she may even be able to run interference for you. If, for instance, he tells you what the position pays, and you tell him that you are earning that amount now and would Like to do a bit better, he might go back to the employer and propose that you be offered an additional 10%.
If no price range is attached to the job, and the interviewer continues to press the subject, then you will have to restpond with a number. You cannot leave the impression that it does not really matter, that you'll accept whatever is offered. If you've been making $80,000 a year, you can't say that a $35,000 figure would be fine without sounding as if you've given up on yourself. (If you are making a radical career change, however, this kind of disparity may be more reasonable and understandable.)
Don't sell yourself short, but continue to stress the fact that the job itself is the most important thing in your mind. The interviewer may be trying to determine just how much you want the job. Don't leave the impression that money is the only thing that is important to you. Link questions of salary to the work itself.
But whenever possible, say as little as you can about salary until you reach the "final" stage of the interview process. At that point, you know that the company is genuinely interested in you and that it is likely to be flexible in salary negotiations.

24. What are your long-range goals?

Refer back to the planning phase of your job search. Don't answer, "I want the job you've advertised." Relate your goals to the company you are interviewing: 'in a firm like yours, I would like to..."

25. How successful do you you've been so far?

Say that, all-in-all, you're happy with the way your career has progressed so far. Given the normal ups and downs of life, you feel that you've done quite well and have no complaints.
Present a positive and confident picture of yourself, but don't overstate your case. An answer like, "Everything's wonderful! I can't think of a time when things were going better! I'm overjoyed!" is likely to make an interviewer wonder whether you're trying to fool him . . . or yourself. The most convincing confidence is usually quiet confidence.

As Reprinted from FOCUS Magazine -- January 5, 1983

article source

0

Interviews: Why should a company hire you?

Sunder Ramachandran artical source
Our earlier feature, 'Smashing answers to common interview questions', got us a phenomenal response. Several readers highlighted the questions they often struggle with. Based on your feedback, here are answers to more interview questions, along with tips from senior HR managers and industry professionals.

Question: Where do you see yourself 5 years from now?

The aim of this question is to test your foresightedness and also gauge if you plan for the future. Stick to professional goals and aspirations while answering. The interviewer does not want to hear about a dream vacation you plan to take, or the industry you would like to be in. Talk about company related objectives. This is an opportunity for you to show that you want to succeed in the company and are keen on creating a career path there.
Sample answer: As your company has a strong performance-based culture, in five years I see myself playing a key role of Brand Manager, working on your marketing initiatives.

  • Tip from Abbas Rizvi, Director, Eternity Placements (New Delhi): "I recommend that candidates give some thought to personal and professional aspirations, and then frame the answer accordingly. Aspiring to be the CEO or Director in five years may be unrealistic for an entry level executive. So, while enthusiasm is appreciated, it has to be aligned with the company's growth plans and the candidates' personal goals."

Question: Why should we hire you?

Being specific and highlighting your strengths versus the competition is the key here. Stay away from generalities like 'I am the best' or 'I am very hard working and dedicated', etc. Talk in quantifiable terms that will make you stand out and pinpoint the qualities you have that are valuable to the company. Give real examples that show them you are best-suited for the job.
Sample answer: In the past, I have implemented projects on attrition management, helping bring down employee turnover rates by 4 per cent. I believe this experience and knowledge will add value as employee retention is amongst your company's top priorities.

  • Tip from M S Ramesh, Senior HR Manager, NTPC (Noida): "I like it when candidates have done some research about our revenue, about the challenges we are facing, before telling us how their experience relates to that. I would recommend that they point out things they may have done in their previous companies that could address our current problems."

Question: What if you don't make it in this interview?

This is often used as a stress question to check your spontaneity. The idea is to see if you have a back up plan and how you handle rejection. You need to be assertive and confident while answering this question. You can say you will be disappointed, adding that you will continue to move ahead in your career with the same enthusiasm and vigour.
Sample answer: I will be disappointed if that happens, but will work on specific feedback and try again when the opportunity presents itself.

  • Tip from Rohini Seth, psychologist and organisational behaviour consultant (New Delhi): "I would recommend that candidates have a back up plan ready -- like going back to their old jobs or joining some other company in a similar field. It pays to be honest and tell the company your plans. I once heard a candidate respond to this question with 'I will join the competitor as I have an offer from them but was keen on working with your brand. We appreciated his honesty and hired him."
Question: Why do you want to make a career in ... (Sales, IT, HR, etc)?
The interviewer wants to learn what you know about the chosen career. Knowledge about the domain and the job shows the interviewer you are interested and demonstrates initiative on your part.
Sample answer: I have always been a people's person and counselling is a skill that comes naturally to me. Armed with a Master's degree in HR, I believe a job as an HR executive will give me an opportunity to put my natural skill sets and education to practice.

  • Tip from Prabh Sharan, Training Manager, Kingfisher Airlines (Mumbai): "I would recommend that candidates present their interest and education as strong reasons for choosing a certain career. If you are making a career shift, then explaining the rational for such a move is also expected. Being honest helps. I interviewed a candidate who said she would like to take up a job that pays her the most and the job we offered fitted that bill as she had some financial responsibilities in the family. She came across as sincere and dedicated, and we offered her the job."
As we said earlier, it's all about the answers.
-- The writer is a corporate training consultant based in New Delhi.