Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have inherited a tomcat application running on RHEL that connects to a local postgres database. We have a total of 8 servers in multiple states running this. Each server actually has two different postgres databases on it. Each day we switch back and forth from one database to the other and the non-live database then gets replaced with new data to switch back the next day.

We are using redir to redirect the database connection in the application. By stopping the redir and re-starting it forwarding he new port we are able to point to the newest data.

The problem comes in when trying to stop the redir and getting FIN_WAITs which can cause a delay of up to a minute. Is there any way to use a redir so that existing connections continue to point to the old location but new ones point to the new port?

share|improve this question
    
I know this doesn't answer your question, but can you give us some insight as to why you do things like this. It doesn't sound very efficient or manageable. –  Dan Dec 14 '12 at 13:40
1  
What an odd way of doing things. Stateful connection tracking in iptables will do what you want. I don't think you can use the usual solutions like pgbouncer when you want to maintain the old connections while switching over. –  Craig Ringer Dec 14 '12 at 13:44
1  
I do it this way because this is the way it was set up when I took over. The data is aggregated and changes are not currently tracked in a way to simply apply updates so they replace the entire database every day. –  user739866 Dec 14 '12 at 13:52
    
@CraigRinger - Do you have any links on iptables setup information like this case? I've tried the following but it does not work: iptables -t nat -A PREROUTING -p udp --dport 5432 -j REDIRECT --to-port 5422 iptables -t nat -A PREROUTING -p tcp --dport 5432 -j REDIRECT --to-port 5422 –  user739866 Dec 14 '12 at 14:32
    
I don't really have any examples; check out the -m state and -m conntrack modules and the iptables documentation. I can't guarantee this approach will work as-is. You might have to use it in combination with packet tagging / labels and then label tests in the PREROUTING rules if you can't use conntrack/state directly in the nat table. Despite being somewhat out of date, check out the Linux Advanced Routing and Traffic Control HOWTO (lartc.org); it might have some guidance. –  Craig Ringer Dec 14 '12 at 14:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.